我想将System.nanoTime()
的结果转换为日期。
public void tempBan(Player p, Player banner, int timeInSeconds){
Long timeInNano = (long) (timeInSeconds * 10^9);
int newTime = (int) (System.nanoTime() + timeInNano);
// here I want to convert newTime to a date
}
我已经通过将秒乘以10^9来将其转换为纳秒。现在,我需要将当前系统时间加上我转换成纳秒的参数转换为日期。
System.nanoTime()
。那里的答案提醒我们,当前的计算机时钟实际上并没有产生任何接近准确的纳秒读数。 - Basil BourqueInstant
和Duration
。请注意,普通的计算机硬件时钟无法以纳秒精度捕捉当前时刻。 - Basil Bourque