A clock providing access to the current instant, date and time using a time-zone.
Instances of this class are used to find the current instant, which can be
interpreted using the stored time-zone to find the current date and time.
As such, a clock can be used instead of system.milliseconds
.
The primary purpose of this abstraction is to allow alternate clocks to be plugged in as and when required. Applications use an object to obtain the current time rather than a static method. This can simplify testing.
Applications should avoid using the top level objects directly.
Instead, they should pass a Clock
into any method that requires it.
A dependency injection framework is one way to achieve this.
This approach allows an alternate clock, such as fixedTime()
to be used during testing.
The systemTime
top level factory method offers clocks based on the best available
system clock, such as system.milliseconds
.
no type hierarchy
no supertypes hierarchy
Inherited Attributes |
Attributes inherited from: Object |
Methods | |
instant | Source Codeshared formal Instant instant() Gets the current instant of the clock. |
milliseconds | Source Codeshared formal Integer milliseconds() Gets the current millisecond instant of the clock. |
Inherited Methods |
Methods inherited from: Object |