javascript instance method
Temporal.ZonedDateTime.prototype.getTimeZoneTransition()
The getTimeZoneTransition() method of ZonedDateTime instances returns a 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
directionoption. This is a convenience overload, sogetTimeZoneTransition(direction)is equivalent togetTimeZoneTransition({ direction }), wheredirectionis a string.
- : A string representing the
options- : An object containing the following property:
direction- : Whether to search before or after the current instant. Must be one of
"next"or"previous".
- : Whether to search before or after the current instant. Must be one of
- : An object containing the following property:
Return value
A ZonedDateTime object with instant t, such that:
- The time zone offset at
tis different from the offset one nanosecond beforet. t < this.epochNanosecondsifdirectionis"previous", ort > this.epochNanosecondsifdirectionis"next".- For all instants between
this.epochNanosecondsandt, 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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.