这是JDK documents 里对System.currentTimeMillis()的返回值的说明 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. 设成5000毫秒,在我的机器上一般总是得到4997,做个实验,如果设成5003,则,结果一般总是5007,有时候5006.如果设成5005,则,结果一般还是5007,如果设成5009,则,结果一般总是5017。大致总是差10毫秒。就像帮助文档里说的一样。很多系统是只能精确到10毫秒的。
'精确也是应该大于5000的基础上又偏差10左右呀'??? 你为什么这样认为呢?是不是被原文中may be larger迷惑了? 原文中may be larger是指我的例子中5003返回5007的情况,不郁闷了吧?
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.
设成5000毫秒,在我的机器上一般总是得到4997,做个实验,如果设成5003,则,结果一般总是5007,有时候5006.如果设成5005,则,结果一般还是5007,如果设成5009,则,结果一般总是5017。大致总是差10毫秒。就像帮助文档里说的一样。很多系统是只能精确到10毫秒的。
你为什么这样认为呢?是不是被原文中may be larger迷惑了?
原文中may be larger是指我的例子中5003返回5007的情况,不郁闷了吧?