java.lang.System.nanoTime()%uA0方法返回最精确的可用系统计时器的当前值,以毫微秒为单位。返回的值表示从一些固定的,任意时间纳秒(在未来,那么值可以是负的),并提供纳秒精度,但不一定是纳秒级的精度。
声明
以下是java.lang.System.nanoTime()方法的声明
public static long nanoTime()
参数
-
NA
返回值
此方法返回系统计时器的当前值,以毫微秒为单位。
异常
-
NA
例子
下面的例子显示java.lang.System.nanoTime()方法的使用。
package com.yiibai 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