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

Temporal.ZonedDateTime.prototype.timeZoneId

· 52CE 我爱测

The **`timeZoneId`** accessor property of Temporal.ZonedDateTime instances returns a string representing the time zone identifier used to interpret the internal instant. The string is either a named identifier in the preferred case (such as `"America/New_York"`), or an offset in

The timeZoneId accessor property of Temporal.ZonedDateTime instances returns a string representing the time zone identifier used to interpret the internal instant. The string is either a named identifier in the preferred case (such as "America/New_York"), or an offset in the form "±hh:mm". If the time zone has aliases, the timeZoneId is the identifier used to create the ZonedDateTime, without canonicalization to the primary identifier.

The set accessor of timeZoneId is undefined. You cannot change this property directly. Use the Temporal/ZonedDateTime/withTimeZone method to create a new Temporal.ZonedDateTime object with the desired new value.

[!NOTE] This string is not intended for display to users. Use Temporal/ZonedDateTime/toLocaleString with the appropriate options to get a localized string.

Examples

Using timeZoneId

const dt = Temporal.ZonedDateTime.from(
  "2021-07-01T12:00:00-07:00[America/Los_Angeles]",
);
console.log(dt.timeZoneId); // "America/Los_Angeles"

const dt2 = Temporal.ZonedDateTime.from("2021-07-01T12:00:00-07:00[-07:00]");
console.log(dt2.timeZoneId); // "-07:00"

const dt3 = dt2.withTimeZone("Asia/Shanghai");
console.log(dt3.timeZoneId); // "Asia/Shanghai"

The timeZoneId is never canonicalized to the primary identifier; it is the same as the one used to create the ZonedDateTime.

const dt = Temporal.ZonedDateTime.from(
  "2021-07-01T12:00:00+07:00[Asia/Ho_Chi_Minh]",
);
const dt2 = Temporal.ZonedDateTime.from(
  "2021-07-01T12:00:00+07:00[Asia/Saigon]",
);
console.log(dt.timeZoneId); // "Asia/Ho_Chi_Minh"
console.log(dt2.timeZoneId); // "Asia/Saigon"

However, presentational differences will get canonicalized.

const dt = Temporal.ZonedDateTime.from(
  "2021-07-01T12:00:00+07:00[asia/ho_chi_minh]",
);
console.log(dt.timeZoneId); // "Asia/Ho_Chi_Minh"

const dt2 = Temporal.ZonedDateTime.from("2021-07-01T12:00:00+07:00[+07]");
console.log(dt2.timeZoneId); // "+07:00"

Specifications

Browser compatibility

See also

  • Temporal.ZonedDateTime
  • Temporal/ZonedDateTime/withTimeZone
  • Temporal/ZonedDateTime/offset
  • Temporal/ZonedDateTime/offsetNanoseconds

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

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

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

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