docs.rodeo

MDN Web Docs mirror

Temporal.Instant

{{JSRef}} {{SeeCompatTable}} 

The Temporal.Instant object represents a unique point in history, with nanosecond precision. It is fundamentally represented as the number of nanoseconds since the Unix epoch (midnight at the beginning of January 1, 1970, UTC), without any time zone or calendar system.

Description

Temporal.Instant is semantically the same as {{jsxref("Date")}} . They both encapsulate a single point in time, but Temporal.Instant is more precise because it stores nanoseconds rather than milliseconds. Temporal.Instant also avoids pitfalls of Date because it does not assume any calendar or time zone information—if you want to read any date or time information such as year or month, you need to convert it to a {{jsxref("Temporal.ZonedDateTime")}}  first, using {{jsxref("Temporal/Instant/toZonedDateTimeISO()", "toZonedDateTimeISO()")}} .

You can convert from Date to Temporal.Instant using the {{jsxref("Date.prototype.toTemporalInstant()")}}  method, which should be preferred over other methods such as {{jsxref("Temporal/Instant/fromEpochMilliseconds", "Temporal.Instant.fromEpochMilliseconds()")}}  because the former involves less user code and may be more optimized. You can also convert from Temporal.Instant to Date using its epoch milliseconds, such as new Date(instant.epochMilliseconds).

RFC 9557 format

Instant objects can be serialized and parsed using the RFC 9557 format, an extension to the ISO 8601 / RFC 3339 format. The string has the following form (spaces are only for readability and should not be present in the actual string):

YYYY-MM-DD T HH:mm:ss.sssssssss Z/±HH:mm

As an input, you may optionally include the time zone identifier and calendar, in the same format as ZonedDateTime, but they will be ignored. Other annotations in the [key=value] format are also ignored, and they must not have the critical flag.

When serializing, you can configure the fractional second digits and offset.

Constructor

Static methods

Instance properties

These properties are defined on Temporal.Instant.prototype and shared by all Temporal.Instant instances.

Instance methods

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN