Get calendar time in nanoseconds
Since the Java doc tells me not to use System.currentTimeMillis
for comparison, I started using System.nanoTime
which is good.
But I ran into some problems, I have to compare events that were in the past.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, xyz);
cal.getTimeMillis();
works great to get the time in milliseconds
, but converting it to nanoseconds
(by multiplying it by 1,000,000) is far from accurate.
How can I get the time of an event in the past in milliseconds?
source to share
A class Calendar
in Java does not contain information about nanoseconds. Therefore you cannot understand it.
You need to store the nanoseconds as : you can't do that either, nanoTime () is not a representation of the current time, but you can still save this to estimate the elapsed time of old processes.long
for the event you want to compare later if you want this detail.
source to share