运用JUC下的TimeUnit(java.util.concurrent.TimeUnit)可进行单位上的直接转换。。。
@Test
public void testNanosecond(){
// 毫秒值
long time = System.currentTimeMillis();
// 纳秒值
long nanosecond = TimeUnit.MILLISECONDS.toNanos(time);
System.out.println(time);
System.out.println(nanosecond);
}
运行结果:
1641264602302
1641264602302000000