【发布时间】:2011-10-22 11:02:23
【问题描述】:
看来System.currentTimeMillis 不是很准确。
查看此示例:
public class MillisTime {
public static void main(String[] args) {
long start = 0;
long end = 0;
while (true) {
if (start == 0) {
start = System.currentTimeMillis();
} else {
long current = System.currentTimeMillis();
if (current != start) {
end = current;
break;
}
}
}
System.out.println("The time interval of your OS: " + (end - start) + "ms");
}
}
结果是(在 Windows XP 上):
The time interval of your OS: 15ms
为什么不是1ms?以及如何获得当前时间的精确毫秒?
【问题讨论】: