目录

static long nanoTime()

描述 (Description)

java.lang.System.nanoTime()方法返回最精确的可用系统计时器的当前值,以纳秒为单位。 返回的值表示纳秒,因为某些固定但是任意时间(将来,因此值可能为负)并提供纳秒级精度,但不一定是纳秒级精度。

声明 (Declaration)

以下是java.lang.System.nanoTime()方法的声明

public static long nanoTime()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回系统计时器的当前值,以纳秒为单位。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.System.nanoTime()方法的用法。

package com.iowiki;
import java.lang.*;
public class SystemDemo {
   public static void main(String[] args) {
      // returns the current value of the system timer, in nanoseconds
      System.out.print("time in nanoseconds = ");
      System.out.println(System.nanoTime());
      // returns the current value of the system timer, in milliseconds
      System.out.print("time in milliseconds = ");
      System.out.println(System.currentTimeMillis());
   }
}  

让我们编译并运行上面的程序,这将产生以下结果 -

time in nanoseconds = 255073580723571
time in milliseconds = 1349311227921
↑回到顶部↑
WIKI教程 @2018