Instant
A moment in time.
A point in time must be uniquely identified, so that it is independent of a time zone. For example, 1970-01-01, 00:00:00
does not represent a moment in time, since this would happen at different times in different time zones: someone in Tokyo would think its already 1970-01-01
several hours earlier than someone in Berlin would. To represent such entities, use LocalDateTime. In contrast, "the moment the clocks in London first showed 00:00 on Jan 1, 2000" is a specific moment in time, as is "1970-01-01, 00:00:00 UTC+0", and so it can be represented as an Instant.
Instant
uses the UTC-SLS (smeared leap second) time scale. This time scale doesn't contain instants corresponding to leap seconds, but instead "smears" positive and negative leap seconds among the last 1000 seconds of the day when a leap second happens.
Some ways in which Instant can be acquired are:
Clock.now can be used to query the current moment for the given clock. With Clock.System, it is the current moment as the platform sees it.
Instant.parse parses an ISO-8601 string.
Instant.fromEpochMilliseconds and Instant.fromEpochSeconds construct the instant values from the amount of time since
1970-01-01T00:00:00Z
(the Unix epoch).
Types
Properties
Returns true if the instant is Instant.DISTANT_FUTURE or later.
Returns true if the instant is Instant.DISTANT_PAST or earlier.
Functions
Compares this
instant with the other instant. Returns zero if this instant represents the same moment as the other (i.e. equal to other), a negative number if this instant is earlier than the other, and a positive number if this instant is later than the other.
Returns an instant that is the result of subtracting the value number of the specified unit from this instant.
Returns an instant that is the result of subtracting components of DateTimePeriod from this instant. The components are subtracted in the order from the largest units to the smallest, i.e. from years to nanoseconds.
Returns a DateTimePeriod representing the difference between other and this
instants.
Returns an instant that is the result of adding the value number of the specified unit to this instant.
Returns an instant that is the result of adding components of DateTimePeriod to this instant. The components are added in the order from the largest units to the smallest, i.e. from years to nanoseconds.
Returns the number of milliseconds from the epoch instant 1970-01-01T00:00:00Z
.
Converts this kotlinx.datetime.Instant value to a java.time.Instant value.