Convert a Time Between Two Timezones in JavaScript
To convert a time between zones, build a Temporal.ZonedDateTime in the source zone and call .withTimeZone(targetZone) — same instant, new wall clock. Part of Working with ZonedDateTime Objects.
Why this scenario is tricky
"3pm in New York, what time in London?" is not offset addition — offsets change with DST and the two zones do not shift on the same day. The correct operation is to anchor the source wall time to an instant, then read that same instant's wall clock in the target zone, which is exactly what withTimeZone does.
Minimal working solution
import { Temporal } from '@js-temporal/polyfill';
const ny = Temporal.ZonedDateTime.from('2024-03-15T15:00:00[America/New_York]');
const london = ny.withTimeZone('Europe/London');
console.log(london.toString()); // same instant, London wall clock
Full production version
import { Temporal } from '@js-temporal/polyfill';
function convertZone(wall: string, from: string, to: string): Temporal.ZonedDateTime {
// Anchor the wall time in the source zone, then re-project.
return Temporal.PlainDateTime.from(wall).toZonedDateTime(from).withTimeZone(to);
}
Verification snippet
Common pitfalls
Frequently Asked Questions
How do I convert a time from one time zone to another?
Build a Temporal.ZonedDateTime in the source zone and call withTimeZone(targetZone). It keeps the same absolute instant and recomputes the wall-clock time for the target zone, correctly accounting for each zone's DST.
Why can't I just add the offset difference between two zones?
Because offsets change with daylight saving and the two zones rarely switch on the same date. A fixed offset gives the wrong answer for part of the year; re-projecting the instant with withTimeZone always uses each zone's rules for that moment.