Firefox Tomorrow

javascript class

Temporal.Instant

View on MDN ↗

The Temporal.Instant object represents a unique point in time, 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 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 ZonedDateTime first, using toZonedDateTimeISO().

You can convert from Date to Temporal.Instant using the toTemporalInstant() method, which should be preferred over other methods such as 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
  • YYYY
    • : Either a four-digit number, or a six-digit number with a + or - sign.
  • MM
    • : A two-digit number from 01 to 12.
  • DD
    • : A two-digit number from 01 to 31. The YYYY, MM, and DD components can be separated by - or nothing.
  • T
    • : The date-time separator, which can be T, t, or a space.
  • HH
    • : A two-digit number from 00 to 23.
  • mm Optional
    • : A two-digit number from 00 to 59. Defaults to 00.
  • ss.sssssssss Optional
    • : A two-digit number from 00 to 59. May optionally be followed by a . or , and one to nine digits. Defaults to 00. The HH, mm, and ss components can be separated by : or nothing. You can omit either just ss or both ss and mm, so the time can be one of three forms: HH, HH:mm, or HH:mm:ss.sssssssss.
  • Z/±HH:mm
    • : Either the UTC designator Z or z, or an offset from UTC in the form + or - followed by the same format as the time component. Note that subminute precision (:ss.sssssssss) may be unsupported by other systems, and is accepted but never output. If an offset is provided, the time is interpreted in the specified offset.

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

  • Temporal.Instant() Experimental
    • : Creates a new Temporal.Instant object by directly supplying the underlying data.

Static methods

Instance properties

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

Instance methods

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also