This feature is not Baseline because it does not work in some of the most widely-used browsers.
The toZonedDateTime() method of Temporal.PlainDateTime instances returns a new Temporal.ZonedDateTime instance representing the same date-time as this plain date-time, but in the specified time zone.
toZonedDateTime(timeZone) toZonedDateTime(timeZone, options)
timeZoneEither a string or a Temporal.ZonedDateTime instance representing the time zone to use. If a Temporal.ZonedDateTime instance, its time zone is used. If a string, it can be a named time zone identifier, an offset time zone identifier, or a date-time string containing a time zone identifier or an offset (see time zones and offsets for more information).
options OptionalAn object containing the following property:
disambiguation OptionalA string specifying what to do when this plain time corresponds to zero or more than one instants in the time zone, usually because of daylight saving time shifts. Possible values are "compatible", "earlier", "later", and "reject". Defaults to "compatible". For more information about these values, see ambiguity and gaps from local time to UTC time.
A new Temporal.ZonedDateTime instance representing the same date-time as this plain date-time, but in the specified time zone.
RangeErrorThrown in one of the following cases:
timeZone is not a valid time zone identifier.options.disambiguation is set to "reject".TypeErrorThrown if any of the arguments are not of the expected type.
const dt = Temporal.PlainDateTime.from("2021-08-01T12:34:56");
const zdt = dt.toZonedDateTime("America/New_York");
console.log(zdt.toString()); // '2021-08-01T12:34:56-04:00[America/New_York]'
const dt2 = Temporal.PlainDateTime.from("2021-01-01T12:34:56");
const zdt2 = dt2.toZonedDateTime("America/New_York");
console.log(zdt2.toString()); // '2021-01-01T12:34:56-05:00[America/New_York]'
Below, we have two wall-clock times that we want to interpret in the America/New_York time zone. The first one, dtNotExist, never existed because of a forward daylight saving time shift, so we need to choose from the times 01:05:00-05:00 or 03:05:00-04:00. The second one, dtAmbiguous, appeared twice because of a backward daylight saving time shift, so we need to choose from the times 01:05:00-04:00 or 01:05:00-05:00. For a more detailed explanation of this situation, see ambiguity and gaps from local time to UTC time.
const dtNotExist = Temporal.PlainDateTime.from("2024-03-10T02:05:00");
const dtAmbiguous = Temporal.PlainDateTime.from("2024-11-03T01:05:00");
// Default: compatible
console.log(dtNotExist.toZonedDateTime("America/New_York").toString());
// '2024-03-10T03:05:00-04:00[America/New_York]'
console.log(dtAmbiguous.toZonedDateTime("America/New_York").toString());
// '2024-11-03T01:05:00-04:00[America/New_York]'
// Use the earlier time for ambiguous times
console.log(
dtNotExist
.toZonedDateTime("America/New_York", { disambiguation: "earlier" })
.toString(),
);
// '2024-03-10T01:05:00-05:00[America/New_York]'
console.log(
dtAmbiguous
.toZonedDateTime("America/New_York", { disambiguation: "earlier" })
.toString(),
);
// '2024-11-03T01:05:00-04:00[America/New_York]'
// Use the later time for ambiguous times
console.log(
dtNotExist
.toZonedDateTime("America/New_York", { disambiguation: "later" })
.toString(),
);
// '2024-03-10T03:05:00-04:00[America/New_York]'
console.log(
dtAmbiguous
.toZonedDateTime("America/New_York", { disambiguation: "later" })
.toString(),
);
// '2024-11-03T01:05:00-05:00[America/New_York]'
// Throw an error for ambiguous times
dtNotExist.toZonedDateTime("America/New_York", { disambiguation: "reject" });
// RangeError: instant is ambiguous
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
toZonedDateTime |
144 | 144 | 139 | No | No | 144 | 139 | No | No | No | 144 | No | ? | 1.40 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime/toZonedDateTime