The java.time classes use the Java time-scale for simplicity.
That scale works on the assumption that the time-line is simple, there are no leap-seconds
and there are always 24 * 60 * 60 seconds in a day. Unfortunately, the Earth's rotation
is not straightforward, and a solar day does not match this definition.
This class is an alternative representation based on the TAI time-scale. TAI is a single incrementing count of SI seconds. There are no leap seconds or other discontinuities.
As a result of the simple definition, this time-scale would make an excellent timestamp. However, there are, at the time of writing, few easy ways to obtain an accurate TAI instant, but it is relatively easy to obtain a GPS instant. GPS and TAI differ by the fixed amount of 19 seconds.
The duration between two points on the TAI time-scale is calculated solely using this class.
Do not use the between method on Duration as that will lose information.
Instead use durationUntil(TaiInstant) on this class.
It is intended that most applications will use the Instant class
which uses the UTC-SLS mapping from UTC to guarantee 86400 seconds per day.
Specialist applications with access to an accurate time-source may find this class useful.
The TAI time-scale is a very simple well-regarded representation of time.
The scale is defined using atomic clocks counting SI seconds.
It has proceeded in a continuous uninterrupted manner since the defined
epoch of 1958-01-01T00:00:00(TAI).
There are no leap seconds or other discontinuities.
This class may be used for instants in the far past and far future. Since some instants will be prior to 1958, it is not strictly an implementation of TAI. Instead, it is a proleptic time-scale based on TAI and equivalent to it since 1958.
This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.
| Modifier and Type | Field and Description |
|---|---|
| private final int | nanos
The number of nanoseconds, later along the time-line, from the seconds field. |
| private static final int | NANOS_PER_SECOND
Constant for nanos per second. |
| private static final Pattern | PARSER
Parse regex. |
| private final long | seconds
The number of seconds from the epoch of 1958-01-01T00:00:00(TAI). |
| private static final long | serialVersionUID
Serialization version. |
| Access | Constructor and Description |
|---|---|
| private | TaiInstant(long
the number of TAI seconds from the epoch taiSeconds, int the nanoseconds within the second, from 0 to 999,999,999 nanoOfSecond)Constructs an instance. |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: the comparator value, negative if less, positive if greaterthe other instant to compare to, not null otherInstant)Implements java. Compares this instant to another based on the time-line. |
| public Duration | Returns: the duration until the specified instant, may be negative, not nullthe instant to calculate the duration until, not null otherInstant)Returns the duration between this instant and the specified instant. |
| public boolean | Returns: true if the other instant is equal to this onethe other instant, null returns false otherInstant)Overrides java. Checks if this instant is equal to the specified |
| public int | Returns: the nanoseconds within the second, from 0 to 999,999,999Gets the number of nanoseconds, later along the time-line, from the start of the second. |
| public long | Returns: the seconds from the epoch of 1958-01-01T00:00:00(TAI)Gets the number of seconds from the TAI epoch of 1958-01-01T00:00:00(TAI). |
| public int | Returns: a suitable hash codeOverrides java. Returns a hash code for this instant. |
| public boolean | Returns: true if this instant is after the specified instantthe other instant to compare to, not null otherInstant)Checks if this instant is after the specified instant. |
| public boolean | Returns: true if this instant is before the specified instantthe other instant to compare to, not null otherInstant)Checks if this instant is before the specified instant. |
| public TaiInstant | |
| public static TaiInstant | |
| public static TaiInstant | Returns: the TAI instant, not nullthe instant to convert, not null instant)Obtains an instance of |
| public static TaiInstant | Returns: the TAI instant, not nullthe number of seconds from the epoch of 1958-01-01T00:00:00(TAI) taiSeconds, long the nanosecond adjustment to the number of seconds, positive or negative nanoAdjustment)Obtains an instance of |
| public static TaiInstant | Returns: the parsed instant, not nullthe text to parse such as "12345.123456789s(TAI)", not null text)Obtains an instance of |
| public TaiInstant | |
| public Instant | Returns: anInstant representing the best approximation of this instant, not nullConverts this instant to an |
| public String | Returns: a representation of this instant, not nullOverrides java. A string representation of this instant. |
| public UtcInstant | Returns: aUtcInstant representing the same instant, not nullConverts this instant to a |
| public TaiInstant | Returns: aTaiInstant based on this instant with the requested nano-of-second, not nullthe nano-of-second, from 0 to 999,999,999 nanoOfSecond)Returns a copy of this |
| public TaiInstant | Returns: aTaiInstant based on this instant with the requested second, not nullthe number of seconds from the epoch of 1958-01-01T00:00:00(TAI) taiSeconds)Returns a copy of this |
| nanos | back to summary |
|---|---|
| private final int nanos The number of nanoseconds, later along the time-line, from the seconds field. This is always positive, and never exceeds 999,999,999. | |
| NANOS_PER_SECOND | back to summary |
|---|---|
| private static final int NANOS_PER_SECOND Constant for nanos per second. | |
| PARSER | back to summary |
|---|---|
| private static final Pattern PARSER Parse regex. | |
| seconds | back to summary |
|---|---|
| private final long seconds The number of seconds from the epoch of 1958-01-01T00:00:00(TAI). | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| TaiInstant | back to summary |
|---|---|
| private TaiInstant(long taiSeconds, int nanoOfSecond) Constructs an instance.
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(TaiInstant otherInstant) Implements java. Compares this instant to another based on the time-line.
| |
| durationUntil | back to summary |
|---|---|
| public Duration durationUntil(TaiInstant otherInstant) Returns the duration between this instant and the specified instant.
This calculates the duration between this instant and another based on
the TAI time-scale. Adding the duration to this instant using
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object otherInstant) Overrides java. Checks if this instant is equal to the specified | |
| getNano | back to summary |
|---|---|
| public int getNano() Gets the number of nanoseconds, later along the time-line, from the start of the second.
The nanosecond-of-second value measures the total number of nanoseconds from
the second returned by
| |
| getTaiSeconds | back to summary |
|---|---|
| public long getTaiSeconds() Gets the number of seconds from the TAI epoch of 1958-01-01T00:00:00(TAI).
The TAI second count is a simple incrementing count of seconds where
second 0 is 1958-01-01T00:00:00(TAI).
The nanosecond part of the second is returned by
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code for this instant.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(TaiInstant otherInstant) Checks if this instant is after the specified instant. The comparison is based on the time-line position of the instants.
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(TaiInstant otherInstant) Checks if this instant is before the specified instant. The comparison is based on the time-line position of the instants.
| |
| minus | back to summary |
|---|---|
| public TaiInstant minus(Duration duration) Returns a copy of this instant with the specified duration subtracted. The duration is subtracted using simple subtraction of the seconds and nanoseconds in the duration from the seconds and nanoseconds of this instant. As a result, the duration is treated as being measured in TAI compatible seconds for the purpose of this method. This instance is immutable and unaffected by this method call.
| |
| of | back to summary |
|---|---|
| public static TaiInstant of(Instant instant) Obtains an instance of Converting a UTC-SLS instant to TAI requires leap second rules. This method uses the latest available system rules. The conversion first maps from UTC-SLS to UTC, then converts to TAI.
Conversion from an
| |
| of | back to summary |
|---|---|
| public static TaiInstant of(UtcInstant instant) Obtains an instance of Converting a UTC instant to TAI requires leap second rules. This method uses the latest available system rules.
The
| |
| ofTaiSeconds | back to summary |
|---|---|
| public static TaiInstant ofTaiSeconds(long taiSeconds, long nanoAdjustment) Obtains an instance of This method allows an arbitrary number of nanoseconds to be passed in. The factory will alter the values of the second and nanosecond in order to ensure that the stored nanosecond is in the range 0 to 999,999,999. For example, the following will result in the exactly the same instant: TaiInstant.ofTaiSeconds(3, 1); TaiInstant.ofTaiSeconds(4, -999999999); TaiInstant.ofTaiSeconds(2, 1000000001);
| |
| parse | back to summary |
|---|---|
| public static TaiInstant parse(CharSequence text) Obtains an instance of The following format is accepted:
The accepted format is strict.
The seconds part must contain only numbers and a possible leading negative sign.
The nanoseconds part must contain exactly nine digits.
The trailing literal must be exactly specified.
This format parses the
| |
| plus | back to summary |
|---|---|
| public TaiInstant plus(Duration duration) Returns a copy of this instant with the specified duration added. The duration is added using simple addition of the seconds and nanoseconds in the duration to the seconds and nanoseconds of this instant. As a result, the duration is treated as being measured in TAI compatible seconds for the purpose of this method. This instance is immutable and unaffected by this method call.
| |
| toInstant | back to summary |
|---|---|
| public Instant toInstant() Converts this instant to an Converting a TAI instant to UTC-SLS requires leap second rules. This method uses the latest available system rules. The conversion first maps from TAI to UTC, then converts to UTC-SLS.
Conversion to an
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. A string representation of this instant.
The string is formatted as | |
| toUtcInstant | back to summary |
|---|---|
| public UtcInstant toUtcInstant() Converts this instant to a Converting a TAI instant to UTC requires leap second rules. This method uses the latest available system rules.
The
| |
| withNano | back to summary |
|---|---|
| public TaiInstant withNano(int nanoOfSecond) Returns a copy of this
The nanosecond-of-second value measures the total number of nanoseconds from
the second returned by This instance is immutable and unaffected by this method call.
| |
| withTaiSeconds | back to summary |
|---|---|
| public TaiInstant withTaiSeconds(long taiSeconds) Returns a copy of this
The TAI second count is a simple incrementing count of seconds where
second 0 is 1958-01-01T00:00:00(TAI).
The nanosecond offset of the second is returned by This instance is immutable and unaffected by this method call.
| |