Wrong Time with System.currentTimeMillis () (Java)

前端 未结 4 1124
太阳男子
太阳男子 2021-02-04 11:10

I made a little program to test the System.currentTimeMillis (). And I have a strange result. This is my logs :

1    26-12-09 20:48:21 - [Log] lTime = 1261860501         


        
4条回答
  •  离开以前
    2021-02-04 11:30

    System.currentTimeMillis() is dependent on System clock. It looks like the system clock has been micro-corrected by an external programme, for Linux that's probably NTP.

    Note you shouldn't use System.currentTimeMillis() to measure elapsed time. It's better to use System.nanoTime() but even that isn't guaranteed to be monotonic.

提交回复
热议问题