Firefox Tomorrow

javascript class

Temporal.PlainDateTime

View on MDN ↗

The Temporal.PlainDateTime object represents a date (calendar date) and time (wall-clock time) without a time zone. It is fundamentally represented as a combination of a date (with an associated calendar system) and a time.

Description

A PlainDateTime is essentially the combination of a PlainDate and a PlainTime. Because the date and time information don’t have much interaction, all general information about date properties is documented in the PlainDate object, and all general information about time properties is documented in the PlainTime object.

If the date-time represents a specific instant that should remain invariant across time zones, you should use the ZonedDateTime object instead. Use PlainDateTime when you need to represent an event happening at a specific wall-clock time that may be a different instant in different time zones.

RFC 9557 format

PlainDateTime 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 [u-ca=calendar_id]
  • 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 Optional
    • : The date-time separator, which can be T, t, or a space. Present if and only if HH is present.
  • HH Optional
    • : A two-digit number from 00 to 23. Defaults to 00.
  • 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.
  • [u-ca=calendar_id] Optional
    • : Replace calendar_id with the calendar to use. See Intl.supportedValuesOf() for a list of commonly supported calendar types. Defaults to [u-ca=iso8601]. May have a critical flag by prefixing the key with !: e.g., [!u-ca=iso8601]. This flag generally tells other systems that it cannot be ignored if they don’t support it. The Temporal parser will throw an error if the annotations contain two or more calendar annotations and one of them is critical. Note that the YYYY-MM-DD is always interpreted as an ISO 8601 calendar date and then converted to the specified calendar.

As an input, you may optionally include the offset and time zone identifier, in the same format as ZonedDateTime, but they will be ignored. Note that the offset must not be Z. 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, whether to display the calendar ID, and whether to add a critical flag for it.

Constructor

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

Static methods

  • Temporal.PlainDateTime.compare()
    • : Returns a number (-1, 0, or 1) indicating whether the first date-time comes before, is the same as, or comes after the second date-time. Equivalent to first comparing their dates, then comparing their times if the dates are the same.
  • Temporal.PlainDateTime.from()
    • : Creates a new Temporal.PlainDateTime object from another Temporal.PlainDateTime object, an object with date and time properties, or an RFC 9557 string.

Instance properties

These properties are defined on Temporal.PlainDateTime.prototype and shared by all Temporal.PlainDateTime 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