如果我理解正确,即使系统时间已更改, usingSystem.nanoTime()
也是一种将标记保持在当前时间的更准确方法。System.currentTimeInMillis()
那么为什么当我将 long 值转换为nanoTime()
对象Calendar
时,输出是错误的呢?
import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
System.out.println(c.get(Calendar.MONTH) + " " + c.get(Calendar.DATE) + " " + c.get(Calendar.YEAR) +
" " + c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND)
+ ":" + c.get(Calendar.MILLISECOND));
}
}