Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.currentTimeMillis(); If I change system time

Tags:

java

time

If I use System.currentTimeMillis() at 00:00 and I get X value.

Then I set the clock back one hour, and after one hour i call System.currentTimeMillis().

Will it return X again, or will it just be X + 3600 * 1000

like image 390
Twinone Avatar asked Mar 25 '13 16:03

Twinone


2 Answers

In a nutshell, whenever you change system time, the value returned by System.currentTimeMillis() will change accordingly.

This is in contrast to System.nanoTime().

like image 181
NPE Avatar answered Nov 15 '22 15:11

NPE


It will return X because System.currentTimeMillis() returns the number of milliseconds since the epoch. That means it will be insynch with your clock and count the number of seconds since January 1, 1970 UTC

like image 33
Oleksi Avatar answered Nov 15 '22 16:11

Oleksi