Since the Java doc tell me, not to use System.currentTimeMillis for comparison, I started using System.nanoTime which is fine.
But I ran into some problems, I have to compare events which are in the past.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, xyz);
cal.getTimeMillis();
works fine to get the time in milliseconds, but converting it to nanoseconds (by multiplying it with 1000000) is far to inaccurate.
How can I get time of a event in the past in milliseconds?
The
Calendarclass in Java doesn’t contain nanosecond information. So you can’t get that.You need to store the nanoseconds as: you can’t do that too, the nanoTime() is not a representation of current time, but you may still store that to evaluate elapsed time of old processes.longfor the event you want to compare later if you need that detail.