System.currentTimeMillis()
当我注意到以下段落出现在其 Javadoc 中时,我正要在 Eclipse 中使用:
Returns the current system time in milliseconds since January 1, 1970
00:00:00 UTC. This method shouldn't be used for measuring timeouts or
other elapsed time measurements, as changing the system time can affect
the results.
所以这意味着我不能依赖System.currentTimeMillis()
我是否想专门维护对这个当前时间点的引用。那么,最准确的方法是什么?这三种方法标记当前时间是否彼此不同?
更新:我想做的是测量两个单独程序运行中两个时间点之间的差异。我担心的是,如果我System.currentTimeMillis()
在第一次运行后使用并且用户使用系统时间,我可能会在第二次运行时得到一个奇怪的意外值。