Here is my modest proposal:
- When the JVM starts
- Call
System.currentTimeMillis()
and store as starting "wall clock" time:long currentTimeMillis0
. - Call
System.nanoTime()
and store as starting "nano" time:long nanoTime0
.
- Call
- Throughout the run of the program, store many timestamps using
System.nanoTime()
.
I am well aware the exact value of a nanoTime is useless by itself, but useful when used in the context of a duration: endNanoTime - beginNanoTime
.
Is it then reasonable, at any nanoTime recorded, to calculate "currentTimeNanos" as:
(1000L * currentTimeMillis0) + (anyNanoTime - nanoTime0)
?