System.currentTimeMillis() returns time in UTC or not??????

Hello Friends,
I want to know that "System.currentTimeMillis()" returns time in UTC or Current Local time
ie suppose i set my TimeZone (GMT+ 2)
then statement gives me value in milliseconds by adding 2 hours to the GMT(Is this value should consider as UTC time or we have to subtract and add offset value according to the timezone.
If time value return by statement is in local time and this is not UTC then is there is any provision in Java to convert local time into UTC time ??
Regards
Gaurav

ejp wrote:
It returns 'the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.'.Which, of course, as I have tried to explain to the OP (but seemingly not very well) that the "current time" referenced must also be the "current time" in UTC. If the starting point is UTC the ending point is UTC (otherwise it doesn't make any sense to measure it that way). I also attempted to tell him that, when he outputs a String representation of that time (i.e. toString or with a DateFormat Object) that the time he sees will be the time according to the TimeZone set in the DateFormat object, or the local timezone when using toString. But, as mentioned, Date objects (and so, essentially, the long value) is always UTC (relevant to the starting point, of course).
A quote from the Date Class
Although the Date class is intended to reflect coordinated universal time (UTC), it may not do so exactly, depending on the host environment of the Java Virtual Machine.which I take to mean that Date is always UTC in so far as the host environment is capable of it.

Similar Messages

  • System.currenttimemillis() returns value ..can't decode it

    Does System.currenttimemillis() return milli seconds elapsed after Jan 1, 1970... does it have no relation with our current time...
    When i did it and print it out .. my millis were the last 3 digits and secs were the 2 dgits before miiliseconds..
    eg: XXXXXXXssmmm
    or was it just a mere coincidence...very confused..

    I was always taught to use Calendar to access individual fields (and DateFormats for formatting and parsings). One reason you aren't supposed to just take the timestamp value (System.currentTimeMillis()) is that there are complications: for example, because of Earth's wobbly orbit there are things called "leap seconds" that may be added to years, so you can't assume each day consists of exactly 24*60*60 seconds (even ignoring DST). But then I wrote this code:
    import java.text.*;
    import java.util.*;
    public class Currently {
        public static void main(String[] args) {
            long now = System.currentTimeMillis();
            Date date = new Date(now);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");
            TimeZone tz = TimeZone.getTimeZone("GMT");
            sdf.setTimeZone(tz);
            String output = sdf.format(date);
            System.out.format("%d --> %s%n", now, output);
            long millis = now % 1000;
            now /= 1000;
            long seconds = now % 60;
            now /= 60;
            long minutes = now % 60;
            now /= 60;
            long hours = now % 24;
            System.out.format("Directly from timestamp %02d:%02d:%02d.%03d%n", hours, minutes, seconds, millis);
    }I'm not suggesting one abandon Calendar and DateFormat, but where are the leap seconds since 1970?

  • Converting value from System.currentTimeMillis() to readable format

    hi
    i have in database coumn with values that were stored as result of executing System.currentTimeMillis() in java (=“the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC). i need to convert these values to some human readable format.
    i am able to get year, month and day from these values(value_date) in format "dd/mm/yyyy" but i need hours, minutes and seconds as well.
    select i have for getting years, months and days:
    select (
    extract (day FROM (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
    || '/'||
    extract (month from (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
    ||'/'||
    extract (year FROM (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
    FROM some_table;
    please advice how to improve this select to get something like "dd/mm/yyyy hh:mm:ss"
    thanks

    Note that the result with to_char might still not be what you expect (due to timezone and/or DTS):
    SQL>  CREATE OR REPLACE FUNCTION currenttimemillis
       RETURN NUMBER
    IS
       LANGUAGE JAVA
       NAME 'java.lang.System.currentTimeMillis() return java.lang.long';
    Function created.
    SQL>  select to_char(sysdate, 'dd.mm.rrrr hh24:mi:ss') dt,
           to_char(date '1970-01-01' + currentTimeMillis/(1000*24*60*60),'dd.mm.rrrr hh24:mi:ss') dt2
      from dual
    DT                  DT2               
    04.06.2009 16:44:09 04.06.2009 14:44:09

  • System.currentTimeMillis() going backwards!!!

    Hi,
    The following program runs a loop, each iteration measuring the time, and ensuring the new time is later than the last measured time.
    I run it like this:
    java -cp . Test 500 1
    My JVM is this:
    ahl84:/nfs/ahl16/users/is/djepson/work/backwards $ java -version
    java version "1.3.1.01-release"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1.01-release-010816-12:37)
    Java HotSpot(TM) Server VM (build 1.3.1 1.3.1.01-release-010816-13:34-PA_RISC2.0 PA2.0, mixed mode)
    On one of our production machines, this program actually reaches the ERROR line - i.e. time is SEEN to go backwards.
    The problem also happens (although less frequently if I use a 0 for the sleep value - i.e. I am not forcing rescheduling on the main thread.
    Please, anyone any ideas???
    The machine in question has 2 CPUs if thats any help, but I can run it on other multi-CPU machines, seemingly without problem.
    public class Test
       public static void main( String[] args )
          for ( int i = 0; i < args.length; i++ )
             System.out.println( "arg[" + i + "]=[" + args[i] + "]" );
          if ( args.length != 2 )
             System.out.println( "Usage:" );
             System.out.println( "java -cp . Test [iterations] [delay (ms)]" );
          else
             Integer iterations = Integer.valueOf( args[0] );
             Integer delay = Integer.valueOf( args[1] );
             Test t = new Test( iterations.intValue(), delay.intValue() );
             t.go();
       public Test( int iterations, int delay )
          _iterations = iterations;
          _delay = delay;
          _errors = 0;
          _lastTime = System.currentTimeMillis();
       public void go()
          System.out.println( "START : Iterations=[" + _iterations + "], delay=[" + _delay + "], time=[" + _lastTime + "]" );
          for ( int i = 0; i < _iterations; i++ )
             long now = System.currentTimeMillis();
             if ( now < _lastTime )
                System.out.println( "Time sequence ERROR, i=[" + i + "], last=[" + _lastTime + "], now=[" + now + "]" );
                _errors++;
             else
                System.out.println( "Time sequence OK,    i=[" + i + "], last=[" + _lastTime + "], now=[" + now + "]" );
                _lastTime = now;
             if ( _delay > 0 )
                try
                   Thread.currentThread().sleep( _delay );
                catch ( InterruptedException e )
                   e.printStackTrace();
          System.out.println( "FINISH : Time=[" + _lastTime + "] errors=[ " + _errors + " / " + _iterations + " (" + ((float)_errors / (float)_iterations * 100) + "%) ]" );
       long _lastTime;
       int  _iterations;
       int  _errors;
       int  _delay;

    I think You may be running into an os/hardware problem. The
    System.currentTimeMillis() returns the number of milli secs since
    sometime in 1970. However the actual resolution of it depends on the operating system and hardware. Its possible that the thread is being
    allcoated to different procs on your machine (after sleeps especially
    and sometimes anyway) and the OS call used by java returns different
    values.
    for some reason I have a hunch that this isn't a java problem as such.
    maybe os/ maybe hardware/ maybe interation of java with both.
    try forcing the VM to run on one processor only.
    matfud

  • Does System.currentTimeMillis() always return correct time?

    Can i rely on it for performance testing?

    It gets the time from the computer the application is running on. I can think of at least three things that will change this time:
    1. A user (or another program) changes the time.
    2. Your operating system changes the time automatically when daylight savings time starts or ends.
    3. NTP (Network Time Protocol) is running on your computer and adjusts the time to match the time on some other computer;.

  • System.currentTimeMillis() not accurate on Windows ?

    Hi,
    JVM : 1.4.2_03-b02
    OS : Windows XP
    processor : XEON 2.4 GHz
    Following test fails with 62.5 error percentage.
    Is it due to windows failing to give time on a millisecond level ?
    Or is there another reason ?
      public void testSleep() throws Exception {
        int total = 1000;
        int errors = 0;
        for ( int j = 0; j < total; j++ ) {
          long start = System.currentTimeMillis();
          Thread.sleep(5);
          long end = System.currentTimeMillis();
          if ( end < start+5 ) {
            errors++;
        Float errorPercentage = new Float( errors*(float)100/total );
        assertEquals( new Float(0), errorPercentage );
      }Regards, Tom.

    The millisecond level of precision is only a possibility provided by the API, the OS does not forcibly provide it.
    But Thread.sleep will not be absolutely precise, it is the most likely culprit.

  • I have a problem sending mail via smtp. I use a satellite system and the average return time for a ping is 675ms. Is this a problem with mail? If so can I change Mail to accept it. The problem also exists with Lion

    I have a problem sending mail via smtp. I use a satellite system and the average return time for a ping is 675ms. Is this a problem with mail? If so can I change Mail to accept it. The problem also exists with Lion and on both my MacPro and my wife's Imac. I also see my mailboxes randomly disconnecting and reconnecting. Any other ideas of a possible cause?

    I solved it myself, after the "note" which came back from FF/Mozilla just as I finished my message, commenting on what it was that my system had , I wnnt back to check my plug-ins etc. I downloaded the latest Java, BOTH 32bit AND 64 bit versions and latest Firefox.
    Now all is working.
    Thanks,
    B.

  • 1 month difference between OS time and System.currentTimeMillis()

    Hi all:)
    System.currentTimeMillis() give a time 1 month ago. If any one have idea what is wrong?Others programs give the right time.
    I tested on Windows XP Pro and Linux end the result is wrong on both OS.
    Thank you in advance.

    posman@linux:~/ivan> uname -a
    Linux linux 2.6.4-52-default #1 Wed Apr 7 02:08:30 UTC 2004 i686 i686 i386 GNU/Linux
    posman@linux:~/ivan> cat x.java
    public class x {
    public static void main(String args[]) {
    System.out.println(new java.util.Date());
    posman@linux:~/ivan> javac x.java
    posman@linux:~/ivan> date;java x
    Mon Feb 14 10:18:02 CET 2005
    Mon Feb 14 10:18:02 CET 2005

  • System.currentTimeMillis() not respecting system clock

    How does System.currentTimeMillis() work? I thought it checked the system clock. But I have an application that monitors the clock and I try to catch changes in it (for instance if the user changes his/her clock during runtime). But the System.currentTimeMillis() seems to ignore the time changes of the sytem clock. Any ideas?

    I had already done that. That is why I posted. I
    could have sworn it worked from previous experience,
    but I am not seeing it work now...The following code:import java.io.*;
    import java.util.*;
    public class TimeDemo {
        public static void main(String[] args) {
            try {
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
                System.out.println(System.currentTimeMillis());
                br.readLine();
                System.out.println(System.currentTimeMillis());
            catch (Exception e) {
                System.out.println(e);
    }Produces the following output:
    $ java TimeDemo
    1120149951371
    1117644363468 You'll note that time appears to have gone backwards - but in fact I set the clock back during the readLine block. So I think it does respond to changing the clock (at least under Solaris on a SPARC with Java 1.5).

  • I cannot do a software update, I get as far as System Updates then when I choose it a message appears say  "Check for update is not available at this time"  but I have not had a system update for a good while now.  I am on System version 6.16.211.XT912.Ve

    I cannot do a software update, I get as far as System Updates then when I choose it a message appears say  "Check for update is not available at this time"  but I have not had a system update for a good while now.  I am on System version 6.16.211.XT912.Verizon,en,US

    Which phone model?

  • TS1538 I have a 4th generation iPod. My system is Windows 7 64-bit. iPod not recognized in iTunes. Also getting iTunes error about cd/dvd drivers not installed. I have reinstalled 4 times and finally got iPod software installed properly. Please help!

    I have a 4th generation iPod. My system is Windows 7, 64-bit. iPod not recognized in iTunes. It is in my computer. Also getting iTunes error message about cd/dvd drivers not properly installed. I've restalled 5 times and still not working.  Finally got iPod software to properly install. Please help!

    Did you try this:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7

  • Will a system restore from Time Machine erase any of the data that is currently on the Mac and not in the Time Machine?

    We had a lot of data on our Mac (i.e. photos, iTunes libraries etc) which we backed up via Time Machine. The hard disk corrupted so we had to get it wiped. When we got it back, my parents started using the mac as per usual but they didn't do a full System Restore from Time Machine. So, if I do a full restore now, will it erase any of the new photos, musc etc that is currently on the mac?

    The Time Machine restore will only restore what is on Time Machine.  Making a clone is probably a better means of ensuring whatever data you want recovered gets recovered together with Time Machine.
    Generally speaking, applications that are newer than the operating system from Apple that are included with the operating system are not supported.  So in your data recovery process from your clone, you'll have to be careful what data you choose to copy back.

  • I have a windows 7 operating system on my laptop and it keeps saying I have installed itunes wrong?? i have done this activity three times now and do not understand the error? what di I have to do to fix the problem?

    i have a windows 7 operating system on my laptop and it keeps saying I have installed itunes wrong?? i have done this activity three times now and do not understand the error? what di I have to do to fix the problem?

    What's the precise text of the error message, please? (There's a few different ones I can think of that you might be getting.)

  • If I restore the system from Time Machine, are folders not in Time Machine erased?

    Pretty much as per the title. I was messing around with my Internet connection (DNS issues) and now can't get online at all, and can't find other ways back online, so I was going to restore from Time Machine: but I've got some folders that aren't in Time Machine (mainly temporary files like podcasts, iTunes U, videos and the like). If I do a system restore from Time Machine, it looks like that material will be erased. Will it all disappear, or will the folders not in Time Machine be left as is?
    Thanks in advance!

    Yes, a time machine restore will erases the volume and then restores.

  • I have an iPad 2, and every time ii attempt to open a new page "about blank" appears. What can I do to get rid of this from my system baring in mind that I am not particularly computer literate.  Many thanks

    I have an I pad 2, and when I attempt to open a new page "about blank" appears. What can I do to remove this from the system baring in mind that I am not particularly co outer literate.
    Many thanks

    Is this in safari?
    try going into settings, safari and clear history. You may also want to clear cookies (means you will need to sign back into sites)
    It's possible that that page is a popup ad of some sort that can't run, for example a flash based ad.  You may have picked the cookie up browsing the internet and now that it's in there the only way to get rid of it is to clear your history and cookies.

Maybe you are looking for

  • Messages not working since HDD replacement

    Hello! So my MBPr stopped booting a week ago and I had to have both fans, the motherboard, HDD, and back plate replaced.  That's done, everything works now except Messages.  I rely on messages to communicate with my team and my family, so this is a b

  • New laptop, ipod doesn't list music

    We set up a new ipod on a desktop then a few months later bought a laptop with vista. When plugging the i pod in it shows the user name but doesn't list what music is on the i pod. Memory at the bottom does indicate music saved as memory has been use

  • About subcontracting process

    Hi Sap Gurus, While doing the GR for subcontracting process I am getting this error message: Field selection for mvmt type 543 / acct 400020 differs for Business Area (033) So what could be the possible solution? Thanks Sha

  • Iphoto won't open, conflict with OS after update.

    I am running an older version of iphoto. Version 8.1.2. I updated my OS recently to 10.8.2 and now iphoto won't open, I am getting a message that it is a software conflict. I know this is a problem people had awhile ago, but I am just updating things

  • How can I update Safari 5.1?

    Many website won't support this version and ask me to update.  I don't really need to pay to update my entire OS.