length of System.currentTimeMillis

anzaan picture anzaan · Feb 5, 2012 · Viewed 27.9k times · Source

Does System.currentTimeMillis always returns a fixed length of value. In my windows Core2, it return a 13 digit long value.

From its API:

Returns the current time in milliseconds. Note that while 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.

Answer

Adam Zalcman picture Adam Zalcman · Feb 5, 2012

System.currentTimeMillis() returns the number of milliseconds since epoch, i.e. since midnight UTC on the 1st January 1970.

You can check when the the number of milliseconds since epoch was 13 decimal digits for the first time. This happened on

Sep 9 2001 at 01:46:40.000 UTC (1'000'000'000'000 ms since epoch)

You can also check when the number of milliseconds since epoch is going to be 13 decimal digits for the last time. This is going to happen on

Nov 20 2286 at 17:46:39.999 UTC (9'999'999'999'999 ms since epoch)

Thus between these two dates, the function will always return 13 decimal digit value assuming the machine has the current time set correctly.

So you're safe with the assumption that the return value is 13 decimal digits for more than the next two centuries.