Skip to main content

NanoClock

Class

trading.keysquare.clock.NanoClock

A high precision clock that can provide the current time in nanoseconds relative to the epoch.

Using a primitive long to store epoch relative time in nanoseconds allows time in the following range to be modelled: 1677-09-21T00:12:43.145224192 to 2262-04-11T23:47:16.854775807.

Example usage:

NanoClock nanoClock = NanoClock.getInstance();
long now = nanoClock.nanoTimeSinceEpoch();

Fields

NANOS_IN_MICROSECOND

long value = 1000

Nanoseconds in a microsecond.

NANOS_IN_MILLISECOND

long value = 1000000

Nanoseconds in a millisecond.

NANOS_IN_SECOND

long value = 1000000000

Nanoseconds in a second.

Methods

long nanoTimeSinceEpoch()

Returns the nano time since epoch.

NanoClock getInstance()

Returns the singleton instance of NanoClock.