Skip to main content

An Iso.Instant is a single point in time (called "exact time"). No time zone is present. As such Iso.Instant has no concept of days, months or even hours.

Accessors and arithmetic operate at millisecond precision, but the string representation itself preserves whatever fractional-second precision was parsed (including sub-millisecond), matching the underlying Temporal behavior.

For convenience of interoperability, instants are represented as an ISO8601 string in Zulu time (UTC). The format looks like 1970-01-01T00:00:00.000Z.

If you have a legacy Date instance, you can use its toISOString() method to convert to an Iso.Instant.

Since Iso.Instant doesn't contain any information about time zones, a Iso.TimeZone is needed in order to convert it into a Iso.DateTime (and from there into any of the other Iso types.)

Like Unix time, Instant ignores leap seconds.

now()

now(): Instant

This method gets the current exact system time, without regard to time zone. This is a good way to get a timestamp for an event, for example. It works like the old-style JavaScript Date.now().

Returns

Instant

an Iso.Instant string representing the current system time.


fromEpochMilliseconds()

fromEpochMilliseconds(epochMilliseconds): Instant

Parameters

epochMilliseconds

number

Returns

Instant


isValid()

isValid(instant): instant is Instant

Parameters

instant

unknown

Returns

instant is Instant


assertIsValid()

assertIsValid(instant): asserts instant is Instant

Parameters

instant

unknown

Returns

asserts instant is Instant


getEpochSeconds()

getEpochSeconds(instant): number

Parameters

instant

Instant

Returns

number


getEpochMilliseconds()

getEpochMilliseconds(instant): number

Parameters

instant

Instant

Returns

number


add()

add(instant, temporalDurationLike): Instant

Here is a comment!

Parameters

instant

Instant

temporalDurationLike

Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }

Returns

Instant


subtract()

subtract(instant, temporalDurationLike): Instant

Parameters

instant

Instant

temporalDurationLike

Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }

Returns

Instant


until()

until(instant, other, options?): Duration

Parameters

instant

Instant

other

Instant

options?

largestUnit?

LargestUnit\<TimeUnit>

smallestUnit?

SmallestUnit\<TimeUnit>

roundingIncrement?

number

roundingMode?

RoundingMode

Returns

Duration


since()

since(instant, other, options?): Duration

Parameters

instant

Instant

other

Instant

options?

largestUnit?

LargestUnit\<TimeUnit>

smallestUnit?

SmallestUnit\<TimeUnit>

roundingIncrement?

number

roundingMode?

RoundingMode

Returns

Duration


round()

round(instant, options): Instant

Parameters

instant

Instant

options

smallestUnit

SmallestUnit\<TimeUnit>

roundingIncrement?

number

roundingMode?

RoundingMode

Returns

Instant


equals()

equals(instant, other): boolean

Parameters

instant

Instant

other

Instant

Returns

boolean


isEqual()

isEqual(instant, other): boolean

alias for equals

Parameters

instant

Instant

other

Instant

Returns

boolean


isBefore()

isBefore(instant, other): boolean

Parameters

instant

Instant

other

Instant

Returns

boolean


isAfter()

isAfter(instant, other): boolean

Parameters

instant

Instant

other

Instant

Returns

boolean


isEqualOrBefore()

isEqualOrBefore(instant, other): boolean

Parameters

instant

Instant

other

Instant

Returns

boolean


isEqualOrAfter()

isEqualOrAfter(instant, other): boolean

Parameters

instant

Instant

other

Instant

Returns

boolean


toZonedDateTime()

toZonedDateTime(instant, timeZone): ZonedDateTime

Parameters

instant

Instant

timeZone

string

Returns

ZonedDateTime


formatISO9075()

formatISO9075(instant): string

Parameters

instant

Instant

Returns

string


toJsDate()

toJsDate(instant): Date

Parameters

instant

Instant

Returns

Date


fromEpochSeconds()

fromEpochSeconds(epochSeconds): Instant

Parameters

epochSeconds

number

Returns

Instant


from()

from(item): Instant

Parameters

item

string

Returns

Instant


compare()

compare(one, two): number

Parameters

one

Instant

two

Instant

Returns

number


chain()

chain(instant): IInstantChain

Parameters

instant

Instant

Returns

IInstantChain