How can I measure time in Java not susceptible to System clock changes?

后端 未结 5 779
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 10:43

I would like to measure elapsed time in a Java. However differences in System.currentTimeMillis() and (I believe) System.nanoTime() can be changed

5条回答
  •  日久生厌
    2021-01-03 11:19

    If you're trying to stop people from subverting a license scheme by setting the clock back, you need to store the highest time you've seen so far in some sort of encrypted and secure storage, and then disable the program if either the time goes less than the highest you've seen (with some allowance for NTP clock adjustments and DST changes of course), or if they somehow tamper with or delete the secure store.

提交回复
热议问题