Java – Monotonically increasing time in Java


In a Java application I want to be able to take a timestamp at the start of an operation and be able to periodically check how long the operation has been running. The catch is: I do not want to be impacted by the Network Time Protocol moving the clock around, or the admin changing the time, or anything which can abruptly adjust the time of day. I want a monotonically increasing time value. I believe this rules out java.util.Date, Time, and Calendar.

Is there some source of a monotonically increasing timestamp in the JRE?

Best Solution

Have you considered using System.nanoTime()?

It is only meaningful in working out elapsed time between two events. Since the documentation states that it is not related to any system or wall time I believe it could be used in your sitatuion.