The Temporal.ZonedDateTime() constructor creates Temporal.ZonedDateTime objects.
This constructor allows you to create instances by directly supplying the underlying data. Like all other Temporal classes, you should usually construct Temporal.ZonedDateTime objects using the Temporal/ZonedDateTime/from static method, which can handle a variety of input types.
Syntax
new Temporal.ZonedDateTime(epochNanoseconds, timeZone)
new Temporal.ZonedDateTime(epochNanoseconds, timeZone, calendar)
[!NOTE]
Temporal.ZonedDateTime()can only be constructed withnew. Attempting to call it withoutnewthrows a TypeError.
Parameters
epochNanoseconds- : A BigInt that corresponds to the Temporal/ZonedDateTime/epochNanoseconds property.
timeZone- : A string that corresponds to the Temporal/ZonedDateTime/timeZoneId property. Unlike all other
TemporalAPIs, it must be a valid time zone identifier (either named or offset) as-is, and cannot be aTemporal.ZonedDateTimeinstance or a date-time string.
- : A string that corresponds to the Temporal/ZonedDateTime/timeZoneId property. Unlike all other
calendar- : A string that corresponds to the Temporal/ZonedDateTime/calendarId property. See
Intl.supportedValuesOf()for a list of commonly supported calendar types. Defaults to"iso8601".
- : A string that corresponds to the Temporal/ZonedDateTime/calendarId property. See
Return value
A new Temporal.ZonedDateTime object, representing the specific instant specified by the parameters.
Exceptions
- TypeError
- : Thrown if
timeZoneorcalendaris not a string.
- : Thrown if
- RangeError
- : Thrown in one of the following cases:
epochNanosecondsis not in the representable range, which is ±10<sup>8</sup> days, or about ±273,972.6 years, from the Unix epoch.timeZoneis not a valid time zone identifier.calendaris not a valid calendar identifier.
- : Thrown in one of the following cases:
Examples
Using Temporal.ZonedDateTime()
const zdt = new Temporal.ZonedDateTime(0n, "America/New_York");
console.log(zdt.toString()); // '1969-12-31T19:00:00-05:00[America/New_York]'
Specifications
Browser compatibility
See also
- Temporal.ZonedDateTime
- Temporal/ZonedDateTime/from
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
