Class MonotonicClock
A clock for measuring how long something has lasted inside this process.
public static class MonotonicClock
- Inheritance
-
MonotonicClock
- Inherited Members
Remarks
DateTime.UtcNow is the wrong clock for a duration. It is the host's wall clock, and NTP
or an operator is free to step it: forward, and everything timed against it ages at once
(every instance within the step of its lifetime cap closes on the next pulse, with its
players inside); backward, and nothing ages until the clock catches up again. A duration
only needs a clock that never goes backwards and never jumps, which is what this is.
The value is seconds from an arbitrary origin, so it means nothing on its own and nothing
outside this process. Only differences between two readings are meaningful. It is
Stopwatch underneath, so it is safe to read from any thread, which
UnityEngine.Time is not.
An instant that has to mean the same thing in another process, or survive a restart, is not a job for this clock. Take it from the database, which every process shares.
Properties
NowSeconds
Seconds on this process's monotonic clock.
public static double NowSeconds { get; }
Property Value
NowTicks
The same reading in TimeSpan ticks (100 ns), for a store that keeps
its instants as longs. It is not a DateTime's ticks, and is
never compared with one.
public static long NowTicks { get; }