Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does System.currentTimeMillis represent UTC time?

Tags:

java

Does System.currentTimeMillis() represent UTC time or local system time?

like image 770
Rajat Gupta Avatar asked Jun 19 '12 14:06

Rajat Gupta


People also ask

What does system currentTimeMillis () do?

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.

Is Java date in UTC?

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.

Is system currentTimeMillis accurate?

Regarding accuracy, you are almost correct. On SOME Windows machines, currentTimeMillis() has a resolution of about 10ms (not 50ms).

Is UTC a milliseconds?

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).


2 Answers

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.)

like image 133
Jon Skeet Avatar answered Sep 18 '22 14:09

Jon Skeet


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."

like image 21
Greyer Sting Avatar answered Sep 19 '22 14:09

Greyer Sting