System.currentTimeMillis() is not accurate on windows XP?

前端 未结 3 664
醉话见心
醉话见心 2020-12-12 04:37

It seems System.currentTimeMillis is not very accurate.

See this sample:

public class MillisTime {
    public static void main(String[]         


        
3条回答
  •  生来不讨喜
    2020-12-12 05:30

    Yes. The javadoc for System.currentTimeMillis() says it:

    Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

    You could use System.nanoTime(), but make sure to read its javadoc to understand its limitations.

提交回复
热议问题