gpt4 book ai didi

Java System.nanoTime() 与 System.currentTimeMillis()。为什么他们有不同的输出?

转载 作者:行者123 更新时间:2023-11-29 06:37:24 26 4
gpt4 key购买 nike

给定以下 Java 代码:

class Tester
{
public static void main(String[] args)
{
System.out.println((System.nanoTime()/1000));
System.out.println(System.currentTimeMillis());
}
}

它给出了输出

26260516785581377785791569

我原以为两者之间会有一点差异,但我错了。
你们知道为什么它会这样吗?

最佳答案

读取方法的javadoc

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative). The same origin is used by all invocations of this method in an instance of a Java virtual machine; other virtual machine instances are likely to use a different origin.

nanoTime() 没有显示时间。

关于Java System.nanoTime() 与 System.currentTimeMillis()。为什么他们有不同的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18513767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com