Does System.currentTimeMillis()
represent UTC time or local system time?
currentTimeMillis() method returns the current time in milliseconds. The unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
Java OffsetDateTime class is one of the important class to get current UTC time. OffsetDateTime is an immutable representation of a date-time with an offset that is mainly used for storing date-time fields into the precision of nanoseconds.
Regarding accuracy, you are almost correct. On SOME Windows machines, currentTimeMillis() has a resolution of about 10ms (not 50ms).
There is no such things as "UTC milliseconds". A millisecond is an SI unit that is one thousandth of a second. ECMAScript Date instances hold a time value that is an offset in milliseconds from 1970-01-01T00:00:00Z (the ECMAScript epoch).
UTC - it's the number of milliseconds since midnight on January 1st 1970 UTC (modulo leap seconds, potentially).
Obviously it's reliant on the local system clock, but it doesn't depend on the local system time zone.
(It's a shame that the Javadoc isn't clearer on this, admittedly.)
UTC according to oracle.com. http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#currentTimeMillis
"currentTimeMillis
Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With