public final class SystemClock extends Object implements TimeSource<Moment>
Represents a clock which is based on the clock of the underlying operating system.
| Modifier and Type | Field and Description |
|---|---|
static SystemClock |
INSTANCE
Standard implementation.
|
static SystemClock |
MONOTONIC
Monotonic clock based on the best available clock of the underlying operating system.
|
| Modifier and Type | Method and Description |
|---|---|
static Moment |
currentMoment()
Equivalent to
SystemClock.INSTANCE.currentTime(). |
Moment |
currentTime()
Yields the current time.
|
long |
currentTimeInMicros()
Yields the current time in microseconds elapsed since
[1970-01-01T00:00:00,000000Z].
|
long |
currentTimeInMillis()
Yields the current time in milliseconds elapsed since
[1970-01-01T00:00:00,000Z].
|
static ZonalClock |
inLocalView()
Creates a local clock in system timezone.
|
static ZonalClock |
inPlatformView()
Creates a local clock in platform timezone.
|
static ZonalClock |
inZonalView(String tzid)
Creates a local clock in given timezone.
|
static ZonalClock |
inZonalView(TZID tzid)
Creates a local clock in given timezone.
|
long |
realTimeInMicros()
Yields the current time in microseconds elapsed since
UTC epoch [1972-01-01T00:00:00,000000Z].
|
SystemClock |
recalibrated()
Recalibrates this instance and yields a new copy.
|
SystemClock |
synchronizedWith(TimeSource<?> clock)
Synchronizes this instance with given time source and yields a new copy.
|
public static final SystemClock INSTANCE
Standard implementation.
The system property "net.time4j.systemclock.nanoTime" controls if this clock is internally
based on the expression System.nanoTime() (if property is set to "true") or
System.currentTimeMillis() (default). The standard case is a clock which is affected by
OS-triggered time jumps and user adjustments so there is no guarantee for a monotonic time.
public static final SystemClock MONOTONIC
Monotonic clock based on the best available clock of the underlying operating system.
A side effect of this implementation can be increased nominal precision up to nanoseconds
although no guarantee is made to ensure nanosecond accuracy. The accuracy is often limited to
milliseconds. However, the main focus and motivation is realizing a monotonic behaviour by
delegating to the use of a monotonic clock of the underlying OS. Equivalent to CLOCK_MONOTONIC
on a Linux-server.
TickProvider.getNanos()public Moment currentTime()
TimeSourceYields the current time.
currentTime in interface TimeSource<Moment>UnixTime object or derivate)public long currentTimeInMillis()
Yields the current time in milliseconds elapsed since [1970-01-01T00:00:00,000Z].
currentTimeInMicros()public long currentTimeInMicros()
Yields the current time in microseconds elapsed since [1970-01-01T00:00:00,000000Z].
If this clock is based only on System.currentTimeMillis()
then this method will just multiply the millisecond value by factor
1000. On many operating systems the precision is limited to
milliseconds. This is even true if this clock is based on
System.nanoTime() because for purpose of calibration even
here the method System.currentTimeMillis() must be accessed
at least one time.
public long realTimeInMicros()
Yields the current time in microseconds elapsed since UTC epoch [1972-01-01T00:00:00,000000Z].
currentTimeInMicros()public static ZonalClock inPlatformView()
Creates a local clock in platform timezone.
Uses the standard clock SystemClock.INSTANCE and the platform timezone data.
Timezone.ofSystem(),
INSTANCE,
TimeZonepublic static ZonalClock inLocalView()
Creates a local clock in system timezone.
Uses the standard clock SystemClock.INSTANCE.
Timezone.ofSystem(),
INSTANCEpublic static ZonalClock inZonalView(TZID tzid)
Creates a local clock in given timezone.
In order to achieve a monotonic zonal clock, users can use the expression
new ZonalClock(SystemClock.MONOTONIC, tzid.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedINSTANCEpublic static ZonalClock inZonalView(String tzid)
Creates a local clock in given timezone.
In order to achieve a monotonic zonal clock, users can use the expression
new ZonalClock(SystemClock.MONOTONIC, tzid.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedINSTANCEpublic static Moment currentMoment()
Equivalent to SystemClock.INSTANCE.currentTime().
INSTANCEpublic SystemClock recalibrated()
Recalibrates this instance and yields a new copy.
This method is only relevant if this clock is operated in monotonic mode. It is strongly advised not to recalibrate during or near a leap second. Please also note that this method might cause jumps in time - even backwards.
MONOTONICpublic SystemClock synchronizedWith(TimeSource<?> clock)
Synchronizes this instance with given time source and yields a new copy.
This method is only relevant if this clock is operated in monotonic mode. It is strongly advised not to recalibrate during or near a leap second. Please also note that this method might cause jumps in time - even backwards.
clock - another clock which this instance should be synchronized withMONOTONICCopyright © 2014–2015. All rights reserved.