System.currentTimeMillis vs System.nanoTime

后端 未结 10 1233
后悔当初
后悔当初 2020-11-21 22:56

Accuracy Vs. Precision

What I would like to know is whether I should use System.currentTimeMillis() or System.nanoTime()<

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 23:04

    System.nanoTime() isn't supported in older JVMs. If that is a concern, stick with currentTimeMillis

    Regarding accuracy, you are almost correct. On SOME Windows machines, currentTimeMillis() has a resolution of about 10ms (not 50ms). I'm not sure why, but some Windows machines are just as accurate as Linux machines.

    I have used GAGETimer in the past with moderate success.

提交回复
热议问题