Interface Instant
- All Superinterfaces:
StringBuilderFormattable
- All Known Implementing Classes:
MutableInstant
Provides methods for obtaining high precision time information similar to the Instant class introduced in Java 8, while also supporting the legacy millisecond precision API.
Depending on the platform, time sources (Clock
implementations) may produce high precision or millisecond
precision time values. At the same time, some time value consumers (for example timestamp formatters) may only be
able to consume time values of millisecond precision, while some others may require a high precision time value.
This class bridges these two time APIs.
- Since:
- 2.11
-
Method Summary
Modifier and TypeMethodDescriptionlong
Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z.long
Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.int
Gets the number of nanoseconds, later along the time-line, from the start of the millisecond.int
Gets the number of nanoseconds, later along the time-line, from the start of the second.Methods inherited from interface org.apache.logging.log4j.util.StringBuilderFormattable
formatTo
-
Method Details
-
getEpochSecond
long getEpochSecond()Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.The epoch second count is a simple incrementing count of seconds where second 0 is 1970-01-01T00:00:00Z. The nanosecond part of the day is returned by
getNanoOfSecond()
.- Returns:
- the seconds from the epoch of 1970-01-01T00:00:00Z
-
getNanoOfSecond
int getNanoOfSecond()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
getEpochSecond()
.- Returns:
- the nanoseconds within the second, always positive, never exceeds
999,999,999
-
getEpochMillisecond
long getEpochMillisecond()Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z.The epoch millisecond count is a simple incrementing count of milliseconds where millisecond 0 is 1970-01-01T00:00:00Z. The nanosecond part of the day is returned by
getNanoOfMillisecond()
.- Returns:
- the milliseconds from the epoch of 1970-01-01T00:00:00Z
-
getNanoOfMillisecond
int getNanoOfMillisecond()Gets the number of nanoseconds, later along the time-line, from the start of the millisecond.The nanosecond-of-millisecond value measures the total number of nanoseconds from the millisecond returned by
getEpochMillisecond()
.- Returns:
- the nanoseconds within the millisecond, always positive, never exceeds
999,999
-