How to get system date and time?

Can someone show me a code on how to get system date and time.
Thanks!

there is one really easy way to get system time, the api gives a great example of code on this. use gregorian calendar, which you'll find in the api under GregorianCalendar. You only need to create one instance of GC, ie Calendar time = new GregorianCalendar();
you save seconds, minute and hours into int values, so you don't have to access the system time every second, you can create a thread which adds one to the int second value, if oyu see what i mean, for example, i have saved the hours, minutes and seconds as int values;
int hour, minute, second;
i can then create a thread (Thread thread = new Thread(this) and run it like:
Calendar time;
int hour, minute, second;
Thread thread = null;
public MyTime() {
hour= time.get(Calendar.HOUR_OF_DAY);
minute = time.get(Calendar.MINUTE);
second = time.get(Calendar.SECOND);
if(thread == null) {
thread = new Thread(this);
thread.start();
public void run() {
Thread t = Thread.currentThread();
while(thread == t) {
thread.sleep(1000);
second++;
if(second > 59)
minute++;
if(minute>59)
hour++;
formatTime();
public void formatTime() {
second = (second > 59? 0 : second);
minute = (minute > 59? 0 : minute);
hour = (hour > 23? 0 : hour);
System.out.println(hour+":"+minute+":"+second);
public static void main(String[] args) {
new MyTime();
I know this looks like gibberish but it should work. If not, try to fix the problem, i have written from memory really but i guarantee you, this gets the time then every second, simply adds one to the second and then formats time. You can also access the day, month and year then format them using the above code. I don't like giving code since you should really do these things yourself but it is 2:04am, i have nothing better to do and i am not tired so i did you a favour - i have become what i always did not want to, someone ho stays upall night writing code.

Similar Messages

  • How to get the date and Time?

    Hi,
    I am using Jdev 11.1.2.0.
    I had one database table. In that table one variable as bgnDtm and the datatype as oracle.jbo.domain.Timestamp. In my Impl class I declare one variable as beginDate(DateType as oracle.jbo.domain.Date).
    Now I am using the conversion as beginDate=(Date) SampleVO.getAttribute("bgnDtm ");.If I using this scenario I got the Type cast error. so how can I separate Date and Time value.
    So how to do. Please provide some suggestions.
    Regards,
    Ragu.

    you can get the time value either from oracle.jbo.domain.Timestamp or from oracle.jbo.domain.Date
    oracle.jbo.domain.Timestamp timeStampDate = (oracle.jbo.domain.Timestamp) SampleVO.getAttribute("bgnDtm");
    Time time;
            try {
                time = timeStampDate.timeValue();
                System.out.println(time);
            } catch (SQLException e) {
                e.printStackTrace();
            java.sql.Date sqlDate=timeStampDate.dateValue();
                oracle.jbo.domain.Date jboDate=new oracle.jbo.domain.Date(sqlDate);
            Time timeValue = jboDate.timeValue();
            System.out.println(timeValue);Edited by: M.Jabr on Dec 23, 2011 1:55 PM

  • [ASK] How to get system date and substring / concate in data manager dynami

    Hello guys.
    I want to run package DM with the input have default value.
    The selection is look like this :
    Dimension : CATEGORY
    Source : PLAN_2011
    Destination : FORECAST_2011
    Dimension : TIME
    Source : 2011.JAN,2011.FEB,2011.MAR,2011.APR,2011.MAY,2011.JUN,2011.JUL,2011.AUG,2011.SEP,2011.OCT,2011.NOV,2011.DEC
    Destination : <same>
    How to get system date year and do the substring / concate ?
    So dimension category source will be PLAN_<YYYY>, destination = FORECAST_<YYYY>
    Dimension source = <YYYY>.JAN,<YYYY>.FEB,<YYYY>.MAR,<YYYY>.APR,<YYYY>.MAY,<YYYY>.JUN,<YYYY>.JUL,<YYYY>.AUG,<YYYY>.SEP,<YYYY>.OCT,<YYYY>.NOV,<YYYY>.DEC
    Depend on year system date.
    Thank you.

    Stuart,How are you storing OnSaleDate. If you are using OnSaleDate as an attribute dimension then you can write a Custom Defined Function to either:1- query your system for the current date and return the number of seconds that have elapsed since 1/1/1970. This is by definition the begining of the Epoch and how Essbase treats Attribute Dimensions of the Date type.public static long getDateInSeconds() {           Calendar cal = Calendar.getInstance();           return cal.getTime().getTime()/1000;}2- Write a Custom Defined Function that will accept the OnSaleDate and return the number of days sincepublic static double daysSince(double myDate) {     return (getDateInSeconds()-myDate )/86400;}

  • How to pass system date and time with tabular from in Update only Mode.

    Dear Friends,
    i have created tabular form with UPDATE Only .here i am assigning work to another multiple users.i want to insert system date and time when i assign work to multiple users.
    How can i insert system date and time into table using tabular form in Update Only Mode.
    beacuse i have pass in default system date it's working only with add row button.
    How can i pass system date and time in update mode in tabular form.
    Thanks

    Hi,
    You just create a trigger on the table on which you build your tabular form:
    e.g:
    CREATE OR REPLACE TRIGGER  "AUDITING"
    before insert or update on "MYTABLE"
    for each row
    begin
        if inserting then
            :new.created_on := localtimestamp;
            :new.created_by := nvl(v('APP_USER'),user);
        elsif updating then
            :new.updated_on := localtimestamp;
            :new.updated_by := nvl(v('APP_USER'),user);
        end if;
    end;Regards,
    Fateh

  • How to get exact date and time difference?

    Hi,
    When i am using the below sql statement:
    SELECT (TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') - to_Date('7/27/2006 8:30:13 AM','MM/DD/YYYY HH:MI:SS AM')) * 24 hours FROM DUAL;
    the output is:
    Hours
    8.50055555555556
    But Actually it is 8.30
    So how can i get exact days and time difference between two dates in Oracle?
    Thanks....
    Regards,
    Suman Sakinala
    Edited by: SSN on Sep 19, 2008 1:27 AM

    Or more clearly (this time I have my date_from and date_to the right way around hehe!)
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (select TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') as dt_to,
      2                    TO_DATE('7/27/2006 08:30:13 AM','MM/DD/YYYY HH:MI:SS AM') as dt_from FROM DUAL)
      3      ,d as (select (dt_to-dt_from)*24 as diff_hrs from t)
      4  -- end of dates
      5  SELECT TRUNC(diff_hrs) as hours
      6        ,TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60) as mins
      7        ,TRUNC(((((diff_hrs) - TRUNC(diff_hrs))*60) - TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60))*60) as secs
      8* FROM d
    SQL> /
         HOURS       MINS       SECS
             8         30          2
    SQL>

  • How to use system date and time

    Hi i am using mysql database.
    my code is import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.http.HttpSession.*;
    import java.io.*;
    import java.sql.*;
    public class TaskA extends HttpServlet
      public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            java.sql.Date Taskdate = new java.sql.Date(System.currentTimeMillis());
            //long Time1 = System.currentTimeMillis();
            String UserName = request.getParameter("UserName");
            String Task = request.getParameter("Task");
            String Assignedby = request.getParameter("Assignedby");
            String Assignedto = request.getParameter("Assignedto");
            String status = request.getParameter("status");
            String Taskdesc = request.getParameter("Taskdesc");
            try
                 Class.forName("com.mysql.jdbc.Driver");
                 Connection con = DriverManager.getConnection("Jdbc:mysql://localhost:3306/sandeep?UserName=;Password=","root","digi");
                 Statement stmt;
                 stmt = con.createStatement();
                   ResultSet rs = stmt.executeQuery("select UserName from Empinfo where UserName ='" +UserName +"'");
                    if(!rs.next())
                         out.println("UserName may not valid ! u r Task was not Allocate successfully");
                   else
                        //rs.getString(1);
                   PreparedStatement st  = con.prepareStatement("insert into Taskinfo values(?,?,?,?,?,?,?)");
                 st.setDate(1,Taskdate);
                 st.setString(2,UserName);
                 st.setString(3,Task);
                 st.setString(4,Assignedby);
                 st.setString(5,Assignedto);
                 st.setString(6,status);
                 st.setString(7,Taskdesc);
                 st.executeUpdate();
                 out.println("<html>");
                 out.println("<body bgcolor =#cdcdb4 >");
                 out.println("your task sent successfully");
                 out.println("</body>");
                 out.println("</html>");
                   rs.close();
              catch(Exception e)
                   out.println("Driver is not found:    "  +e);
    }and afrer it get execute only date is store in database but not system time.but i want to store both date and time together.
    i am using DATETIME datatype in mysql.
    whats a problem in my code.

    You might want to use TimeStamp and not java.sql.Date which by definition does not include time.
    You might also want to close PreparedStatement and Connection in your code.

  • How to get server date and time using java code

    Hi,
    I'm new to java. I have one doubt about getting date and time of the server. can anyone give some sample code to get that.
    thanks in regards
    Gopi.

    you need 2 things
    1. something on the application server which exposes the servers time/date
    2. something on the client which makes use of your time service
    for instance, you could write a ServerTimeServlet that clients can call to get the time according to the server. or, if you've got a database in the server, often database software will provide a Time procedure or similar that does this, so you can use a simple SQL query to get the latest time

  • How to get the date and time of the last KM scheduled run

    Hi Experts,
    I had a scenario where i need to send the last date and last time when the KM schduler runned.?
    Issue:
    I have created a Km sheduler, in that i have written the jave code to retrieve the details from a function module and getting the output from Func module and sending an email  to one administrator.It worked fine for me.this scheduler will run for every 20 mins.
    But now Abapers have included two import parameters in their Function module " Last date and last run".So i need to populate this iimport parameters dynamically.
    How can i acheive this?
    Please assist.Thanks in Advance.
    Thanks
    Sony.

    java.util.Date date = java.util.Calendar.getInstance().getTime(); //retrieve a date object
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(dd-MMM-yyyy);
    String s = df.format(date); //10-Aug-2001
    String t = "15042001";
    df.applyPattern("ddMMyyyy");
    d = df.parse(t);
    df.applyPattern("dd-MMM-yyyy");
    t = df.format(d); //15-Apr-2001Hey it's Friday, I'm bored

  • Does anyone know how to get specific date and time on an itouch

    I need secific times on  safari searches in my history, there is a legal implication and I need to know if its possible to get the info, or can an apple store get anything. the history is in there but it just gives the date not time.
    Thanks in advance

    a) Open the document with it's password.
    b) Pick "Duplicate" from the File Menu
    c) Pick "Save As..." from the File Menu.

  • Camileo S20 - How to display the date and time

    Hi, to all. I have got as Christmas present the Camileo S20 and I am not able to display the date and time at video. In manual is no mention about this, just how to set the correct date and time. But what is intention of setting the date and time into camera, if it is not possible to display them on video ?

    Hi,
    of course, I did it repeatly, it is written in my question above. I am not stupid.
    This question is aimed to owners of camera Camileo S20 and also Camileo S10 - Camileo S20 is derived of Camileo S10, may be any of them discovered the way how to get the date and time into video.

  • I need to get the Current System Date and time in the format

    I need to get the Current System Date and time in the format
    *6/24/2009 11:30:29 AM*
    How do i do it ?

    I seem to be saying this a lot lately.
    Google is your friend.
    I googled "java current date format" and SimpleDateFormat featured prominently in the results.

  • How can I  get System dates  with time scheduler using threads

    how can I get System dates with time scheduler using threads.is there any idea to update Date in my application along with system Date automatic updation...

    What the heck are you talking about and whatr has it to do with threads?
    Current time: System.currentTimeMillis. Date instances are not supposed to be updated.

  • How can I get the date and time and display it on the report main page?

    Gurus,
    How can I get the date and time and display it on the report main page?
    Thanks!

    Hello,
    You can create a Formula Colum returning a date :
    function CF_1Formula return Date is
    begin
    RETURN(SYSDATE);
    end;
    Put a Field in the Layout having this formula column as source .
    Regards

  • Get  current date and time

    hello.
    How can I get current date and time in JAVA?
    Thanks.

    Sorry, I mean:
    how can I get the value of DATE, MONTH, and YEAR of the
    current date?
         Date date = new Date();
         System.out.println(date);

  • Extracting Time without using the System Date and Time

    Hi, can I know how to process a task at this particular time eg. 6PM everyday without using the System Date and Time..
    Do I need to use a Timer to get this done or is there any other solution to do this? Can give me a few hints? Thanks in advance =D

    You could use a timer...assuming you had some good reference point when you started so you would know that from your starting point it's now 6pm.
    I thought I saw you asked this question once already...and you were given a similar answer....I think by Sylviae?

Maybe you are looking for

  • X1 Carbon Gen3 (2015) Chassis constantly clicks in and out of position

    It's been 1 week since I received my first Lenovo Laptop - X1 Carbon Gen3 and I'm very pleased with it so far. Since the beginning I noticed a 'clicking' sound produced when resting my palms on the keyboard to type, but couldn't figured out what it w

  • HT203052 Lost Cloud docs after upgrade to Yosemite

    I put in a new SSD and upgraded my MBP to Yosemite. All good---except some docs I had written using Text Editor are now somehow just gone. Evidently these were saved to Documents in the Cloud, which is now just gone...?? In Snow Leopard, my last OS,

  • I Lost all my informatio​n and i NEED IT BACK

    i just started my palm tx this morning and it got stuck and then turned on to factory  status.  now i just re formated my laptop and was going to reinstall the palm cd so i can have it on my laptop. but now i cant. I am very upset. i called the suppo

  • ?PSE 7

    I recently purchased pse 7 and every time I click on the icon to open it, I get the welcome page.I then X that out and have to wait again for the program to open. How do I get rid of the welcome/account page and have just the program open?

  • How do you import audio books so they are like the ones you buy from itunes

    how do you import audio books so they are like the ones you buy from itunes?