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

Temporal.ZonedDateTime.prototype.getTimeZoneTransition()

· 52CE 我爱测

The **`getTimeZoneTransition()`** method of Temporal.ZonedDateTime instances returns a Temporal.ZonedDateTime object representing the closest instant after or before this instant at which the time zone's UTC offset changes (the returned instant is the first instant after the chan

The getTimeZoneTransition() method of Temporal.ZonedDateTime instances returns a Temporal.ZonedDateTime object representing the closest instant after or before this instant at which the time zone's UTC offset changes (the returned instant is the first instant after the change), or null if there is no such transition. This is useful for finding out the offset rules of a time zone, such as its daylight saving time pattern.

Note that instants returned about the future may be unreliable, for example due to changes to the time zone definitions.

Syntax

getTimeZoneTransition(direction)
getTimeZoneTransition(options)

Parameters

  • direction
    • : A string representing the direction option. This is a convenience overload, so getTimeZoneTransition(direction) is equivalent to getTimeZoneTransition({ direction }), where direction is a string.
  • options
    • : An object containing the following property:
      • direction
        • : Whether to search before or after the current instant. Must be one of "next" or "previous".

Return value

A Temporal.ZonedDateTime object with instant t, such that:

  • The time zone offset at t is different from the offset one nanosecond before t.
  • t < this.epochNanoseconds if direction is "previous", or t > this.epochNanoseconds if direction is "next".
  • For all instants between this.epochNanoseconds and t, exclusive, the offset is constant.

If there is no such transition, null is returned.

Examples

Finding the next time zone transition

const dt = Temporal.ZonedDateTime.from("2024-01-01T00-05:00[America/New_York]");
const transition = dt.getTimeZoneTransition("next");
console.log(transition.toString()); // "2024-03-10T03:00:00-04:00[America/New_York]"

const transition2 = transition.getTimeZoneTransition("next");
console.log(transition2.toString()); // "2024-11-03T01:00:00-05:00[America/New_York]"

const transition3 = dt.getTimeZoneTransition("previous");
console.log(transition3.toString()); // "2023-11-05T01:00:00-05:00[America/New_York]"

const dt2 = Temporal.ZonedDateTime.from("2024-01-01T00Z[UTC]");
console.log(dt2.getTimeZoneTransition("next")); // null

Specifications

Browser compatibility

See also

  • Temporal.ZonedDateTime
  • Temporal/ZonedDateTime/with
  • Temporal/ZonedDateTime/add
  • Temporal/ZonedDateTime/subtract
  • Temporal/ZonedDateTime/timeZoneId
  • Temporal/ZonedDateTime/offset

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

资料来源与适用范围

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

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

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