大网数据广告活动
Web 标准与前端开发

Temporal.ZonedDateTime() constructor

· 52CE 我爱测

The **`Temporal.ZonedDateTime()`** constructor creates Temporal.ZonedDateTime objects.

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 with new. Attempting to call it without new throws 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 Temporal APIs, it must be a valid time zone identifier (either named or offset) as-is, and cannot be a Temporal.ZonedDateTime instance or a date-time string.
  • 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".

Return value

A new Temporal.ZonedDateTime object, representing the specific instant specified by the parameters.

Exceptions

  • TypeError
    • : Thrown if timeZone or calendar is not a string.
  • RangeError
    • : Thrown in one of the following cases:
      • epochNanoseconds is not in the representable range, which is ±10<sup>8</sup> days, or about ±273,972.6 years, from the Unix epoch.
      • timeZone is not a valid time zone identifier.
      • calendar is not a valid calendar identifier.

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。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。