JavaScript Temporal API: The Complete Guide to Dates, Times, and Time Zones
Learn the Temporal API, JavaScript's modern replacement for Date. Covers Instant, ZonedDateTime, PlainDate, Duration, time zone and DST handling, date arithmetic, formatting, serialization, migrating from Date, and polyfills with practical examples.
Table of Contents
- Introduction
- What’s Wrong with Date
- The Temporal Type System
- Getting the Current Time
- Creating and Parsing Values
- Plain Types: Dates Without Time Zones
- Instant: Exact Points in Time
- ZonedDateTime: Time Zones Done Right
- Date Arithmetic
- Durations
- Comparing and Sorting
- Rounding
- Formatting for Users
- Serialization and Storage
- Migrating from Date
- Browser Support and Polyfills
- Common Pitfalls
- Best Practices
- Conclusion
Introduction
JavaScript’s Date object was copied from Java in 1995, in about ten days. Java deprecated most of its version two years later. JavaScript kept its version for nearly three decades, and an entire ecosystem of libraries (Moment.js, date-fns, Luxon, Day.js) grew up around it to paper over the gaps.
Temporal is the replacement. It’s a new global namespace with a set of immutable types that separate concepts Date lumps together: an exact moment, a calendar date, a wall-clock time, a time zone, and a length of time. It handles time zones and daylight saving time correctly, does calendar-aware arithmetic, and parses only well-defined formats.
After years as a Stage 3 proposal, Temporal now ships natively in Firefox and Chromium-based browsers, with polyfills covering everything else. That makes this a good time to learn it properly.
This guide covers:
- Why
Dateis so error-prone, and how Temporal’s types fix it - Which type to use for which job
- Time zones, DST, and the
disambiguationoption - Date arithmetic, durations, comparisons, and rounding
- Formatting, serialization, and database storage
- Migrating an existing codebase from
Dateand date libraries
What’s Wrong with Date
Before looking at Temporal, it helps to be precise about what it replaces. Date has problems at every level.
It’s Mutable
const start = new Date("2026-10-27");const end = start;end.setDate(end.getDate() + 7);
console.log(start.toISOString()); // 2026-11-03... start changed too!Any function that receives a Date can modify it. Defensive copying (new Date(date)) is the only protection.
Months Are Zero-Indexed (Days Aren’t)
new Date(2026, 1, 1); // February 1st, not January 1stnew Date(2026, 12, 1); // Silently rolls over to January 1st, 2027It Only Knows Two Time Zones
A Date is a timestamp. It can show that timestamp in UTC or in the user’s local time zone, and nothing else. There’s no way to ask “what time is it in Tokyo?” without converting to a string through Intl.
Parsing Is Inconsistent
new Date("2026-10-27"); // Midnight UTCnew Date("2026-10-27T00:00"); // Midnight local timenew Date("10/27/2026"); // Implementation-defined formatnew Date("2026-02-31"); // Invalid Date in some engines, March 3rd in others historicallyA date-only ISO string is parsed as UTC, but a date-time string without an offset is parsed as local time. This one rule has caused countless “off by one day” bugs for users west of Greenwich.
It Conflates Different Concepts
A birthday, a meeting, a log timestamp, and a store’s opening hours are all different kinds of data:
| Data | What it really is |
|---|---|
| Birthday | A calendar date, no time, no time zone |
| Store opens at 9:00 | A wall-clock time, no date |
| Server log entry | An exact moment, time zone irrelevant |
| Meeting in Berlin | A date, time, and a specific time zone |
| Credit card expiry 10/28 | A year and month only |
Date represents all of them as “milliseconds since 1970 in UTC”, so you’re constantly converting and hoping nothing shifts. Store a birthday as new Date("1990-05-14"), display it in California, and it becomes May 13th.
The Temporal Type System
Temporal gives each of those concepts its own type. Every type is immutable: methods return new objects instead of changing the original.
Exact time (a moment on the timeline) ┌────────────────────────────────────┐ │ Temporal.Instant │ │ Temporal.ZonedDateTime ◄── also has a time zone └────────────────────────────────────┘
Wall-clock time (no time zone) ┌────────────────────────────────────┐ │ Temporal.PlainDateTime │ │ Temporal.PlainDate │ │ Temporal.PlainTime │ │ Temporal.PlainYearMonth │ │ Temporal.PlainMonthDay │ └────────────────────────────────────┘
Length of time ┌────────────────────────────────────┐ │ Temporal.Duration │ └────────────────────────────────────┘| Type | Example | Use for |
|---|---|---|
Instant | 2026-10-27T09:30:00Z | Log timestamps, createdAt, events |
ZonedDateTime | 2026-10-27T10:30:00+01:00[Europe/Berlin] | Meetings, flights, anything scheduled |
PlainDate | 2026-10-27 | Birthdays, holidays, due dates |
PlainTime | 09:00:00 | Opening hours, alarms |
PlainDateTime | 2026-10-27T09:00:00 | Form input before a zone is known |
PlainYearMonth | 2026-10 | Card expiry, monthly reports |
PlainMonthDay | 10-27 | Recurring anniversaries |
Duration | PT1H30M | Timers, video length, SLA windows |
The key mental split is exact time versus wall-clock time. An Instant is the same moment for everyone on Earth. A PlainDateTime of “2026-10-27 09:00” is a different moment in every time zone, so Temporal won’t let you treat it as a moment until you supply one.
There are no TimeZone or Calendar classes. Time zones are plain IANA identifier strings like "Europe/Berlin", and calendars are strings like "iso8601" or "hebrew".
Getting the Current Time
Temporal.Now replaces Date.now() and new Date():
Temporal.Now.instant(); // Exact current momentTemporal.Now.timeZoneId(); // "Europe/Berlin" (the system time zone)Temporal.Now.zonedDateTimeISO(); // Now, in the system time zoneTemporal.Now.zonedDateTimeISO("Asia/Tokyo"); // Now, in TokyoTemporal.Now.plainDateISO(); // Today's date in the system time zoneTemporal.Now.plainDateISO("America/New_York"); // Today's date in New YorkTemporal.Now.plainTimeISO(); // Current wall-clock timeThe ISO suffix means “use the ISO 8601 calendar”, which is the Gregorian calendar you almost certainly want.
Note that “today” depends on where you are. At 23:00 in New York, it’s already tomorrow in Berlin. Temporal.Now.plainDateISO() makes you think about that, whereas new Date() hides it.
Creating and Parsing Values
Every type has a static from() method that accepts either an ISO 8601 string or a property bag:
// From stringsconst date = Temporal.PlainDate.from("2026-10-27");const time = Temporal.PlainTime.from("14:30");const instant = Temporal.Instant.from("2026-10-27T13:30:00Z");const meeting = Temporal.ZonedDateTime.from( "2026-10-27T14:30:00[Europe/Berlin]",);
// From property bags. Months are 1-indexed!const date2 = Temporal.PlainDate.from({ year: 2026, month: 10, day: 27 });const meeting2 = Temporal.ZonedDateTime.from({ timeZone: "America/New_York", year: 2026, month: 12, day: 1, hour: 9,});Strict Parsing
Temporal only accepts well-defined formats. There’s no guessing:
Temporal.PlainDate.from("10/27/2026"); // RangeErrorTemporal.Instant.from("2026-10-27T09:00:00"); // RangeError: no offset, not an exact timeThe second error is a feature. A string without a Z or offset doesn’t identify a moment, so it can’t become an Instant.
Handling Invalid Values with overflow
What happens with February 31st? You choose, using the overflow option:
Temporal.PlainDate.from({ year: 2026, month: 2, day: 31 });// 2026-02-28 (default: "constrain" clamps to the nearest valid value)
Temporal.PlainDate.from( { year: 2026, month: 2, day: 31 }, { overflow: "reject" },);// RangeErrorUse "reject" when validating user input. A form that accepts “February 31st” and silently saves February 28th is a bug.
Note that ISO strings are always strict: Temporal.PlainDate.from("2026-02-31") throws regardless of the option.
Modifying with with()
Since values are immutable, you derive new ones with with():
const date = Temporal.PlainDate.from("2026-10-27");
date.with({ day: 1 }); // 2026-10-01 (first of the month)date.with({ month: 12, day: 25 }); // 2026-12-25date.with({ day: date.daysInMonth }); // 2026-10-31 (last of the month)
console.log(date.toString()); // 2026-10-27, unchangedPlain Types: Dates Without Time Zones
Plain types are for values that don’t refer to a specific moment. They’re the right default for most calendar data in a UI.
PlainDate
const date = Temporal.PlainDate.from("2026-10-27");
date.year; // 2026date.month; // 10date.day; // 27date.dayOfWeek; // 2 (Monday = 1, Sunday = 7)date.dayOfYear; // 300date.weekOfYear; // 44date.daysInMonth; // 31date.inLeapYear; // falsedate.monthCode; // "M10"A birthday stored as a PlainDate is May 14th everywhere in the world. It never shifts when someone views it from another continent.
PlainTime
const opens = Temporal.PlainTime.from("09:00");const closes = Temporal.PlainTime.from("17:30");const now = Temporal.Now.plainTimeISO();
const isOpen = Temporal.PlainTime.compare(now, opens) >= 0 && Temporal.PlainTime.compare(now, closes) < 0;PlainDateTime
A PlainDateTime is what an <input type="datetime-local"> gives you: a date and time with no zone. Treat it as an intermediate value and convert it to a ZonedDateTime once you know the zone:
const input = document.querySelector('input[type="datetime-local"]');const local = Temporal.PlainDateTime.from(input.value); // "2026-11-05T15:00"
const scheduled = local.toZonedDateTime("Europe/Berlin");PlainYearMonth and PlainMonthDay
// Credit card expiryconst expiry = Temporal.PlainYearMonth.from("2028-10");const thisMonth = Temporal.Now.plainDateISO().toPlainYearMonth();const expired = Temporal.PlainYearMonth.compare(expiry, thisMonth) < 0;
// Recurring anniversary: what date is it this year?const anniversary = Temporal.PlainMonthDay.from("02-29");anniversary.toPlainDate({ year: 2027 }); // 2027-02-28 (constrained)anniversary.toPlainDate({ year: 2028 }); // 2028-02-29Combining Plain Types
const date = Temporal.PlainDate.from("2026-12-24");const time = Temporal.PlainTime.from("18:00");
date.toPlainDateTime(time); // 2026-12-24T18:00:00date.toZonedDateTime({ timeZone: "Europe/Vienna", plainTime: time });date.toZonedDateTime("Europe/Vienna"); // Start of that day in ViennaInstant: Exact Points in Time
An Instant is a point on the global timeline with nanosecond precision. It has no time zone, no calendar, and no concept of “days” or “months”. It’s the Temporal equivalent of a Unix timestamp, and the closest thing to what Date actually is.
const instant = Temporal.Now.instant();
instant.epochMilliseconds; // 1793093400000instant.epochNanoseconds; // 1793093400000000000n (a BigInt)instant.toString(); // "2026-10-27T09:30:00.123456789Z"
Temporal.Instant.fromEpochMilliseconds(1793093400000);Use Instant for anything that records when something happened: createdAt, audit logs, analytics events, cache expiry. These values never need a time zone until you show them to a human.
To display an Instant, project it into a time zone:
const event = Temporal.Instant.from("2026-10-27T09:30:00Z");
event.toZonedDateTimeISO("Europe/Berlin").toString();// "2026-10-27T10:30:00+01:00[Europe/Berlin]"
event.toZonedDateTimeISO("Asia/Tokyo").toString();// "2026-10-27T18:30:00+09:00[Asia/Tokyo]"Since an Instant has no calendar, you can only add or subtract units of fixed length (hours and smaller):
instant.add({ hours: 24 }); // Fineinstant.add({ days: 1 }); // RangeError: a "day" isn't fixed length without a zoneThat error encodes a real truth: a day is 23 or 25 hours long when the clocks change.
ZonedDateTime: Time Zones Done Right
ZonedDateTime is an exact moment plus a time zone plus a calendar. It’s the most capable Temporal type and the one to use for anything a human schedules.
const meeting = Temporal.ZonedDateTime.from( "2026-11-05T15:00:00[Europe/Berlin]",);
meeting.timeZoneId; // "Europe/Berlin"meeting.offset; // "+01:00"meeting.hour; // 15meeting.hoursInDay; // 24meeting.toInstant(); // The exact momentConverting Between Time Zones
const meeting = Temporal.ZonedDateTime.from( "2026-11-05T15:00:00[Europe/Berlin]",);
meeting.withTimeZone("America/New_York").toPlainTime().toString(); // "09:00:00"meeting.withTimeZone("Asia/Kolkata").toPlainTime().toString(); // "19:30:00"withTimeZone() keeps the same moment and changes how it’s displayed. That’s exactly what a “show this meeting in my time zone” feature needs.
Daylight Saving Time
DST transitions create two awkward cases:
- Gaps: in spring, clocks jump forward and some wall-clock times don’t exist
- Overlaps: in autumn, clocks fall back and some wall-clock times happen twice
In Europe on 2026-03-29, clocks jump from 02:00 to 03:00. In 2026-10-25, they fall back from 03:00 to 02:00. Temporal makes you decide what to do with those times through the disambiguation option:
// 02:30 doesn't exist on 2026-03-29 in Berlinconst gap = { timeZone: "Europe/Berlin", year: 2026, month: 3, day: 29, hour: 2, minute: 30,};
Temporal.ZonedDateTime.from(gap); // 03:30+02:00 ("compatible", the default)Temporal.ZonedDateTime.from(gap, { disambiguation: "earlier" }); // 01:30+01:00Temporal.ZonedDateTime.from(gap, { disambiguation: "later" }); // 03:30+02:00Temporal.ZonedDateTime.from(gap, { disambiguation: "reject" }); // RangeError
// 02:30 happens twice on 2026-10-25 in Berlinconst overlap = { timeZone: "Europe/Berlin", year: 2026, month: 10, day: 25, hour: 2, minute: 30,};
Temporal.ZonedDateTime.from(overlap); // 02:30+02:00 (first occurrence)Temporal.ZonedDateTime.from(overlap, { disambiguation: "later" }); // 02:30+01:00The default, "compatible", matches what Date and most other systems do, so it’s a sensible choice. Use "reject" when you’d rather ask the user than guess.
hoursInDay tells you how long a particular day actually is:
Temporal.ZonedDateTime.from("2026-03-29T12:00[Europe/Berlin]").hoursInDay; // 23Temporal.ZonedDateTime.from("2026-10-25T12:00[Europe/Berlin]").hoursInDay; // 25Time Zone Rule Changes
Governments change time zone rules, sometimes with little notice. If you store a future event as 2027-06-01T10:00:00+03:00[Europe/Istanbul] and the rules change, the stored offset and the time zone now disagree. The offset option controls how parsing resolves that conflict:
Temporal.ZonedDateTime.from(stored, { offset: "prefer" }); // Default: use offset if still valid, else keep wall timeTemporal.ZonedDateTime.from(stored, { offset: "ignore" }); // Keep the wall-clock time (10:00 local)Temporal.ZonedDateTime.from(stored, { offset: "use" }); // Keep the exact momentTemporal.ZonedDateTime.from(stored, { offset: "reject" }); // Throw on mismatchFor a calendar app, "ignore" is usually right: a 10:00 meeting should still be at 10:00 after the rules change.
Date Arithmetic
Temporal arithmetic is calendar-aware and DST-aware. Use add() and subtract() with a duration or property bag:
const date = Temporal.PlainDate.from("2026-10-27");
date.add({ days: 7 }); // 2026-11-03date.add({ months: 1 }); // 2026-11-27date.subtract({ years: 1, days: 1 }); // 2025-10-26date.add({ weeks: 2 }); // 2026-11-10Month-End Overflow
Adding a month to January 31st has no perfect answer. Temporal constrains by default:
const jan31 = Temporal.PlainDate.from("2026-01-31");
jan31.add({ months: 1 }); // 2026-02-28jan31.add({ months: 1 }, { overflow: "reject" }); // RangeErrorBe careful when generating a recurring monthly schedule. Adding a month repeatedly to the previous result drifts (Jan 31 → Feb 28 → Mar 28). Always add from the original start date instead:
const start = Temporal.PlainDate.from("2026-01-31");
// ❌ Drifts to the 28th after Februarylet current = start;const drifting = [];for (let i = 0; i < 4; i++) { drifting.push(current); current = current.add({ months: 1 });}
// ✅ Stays on the last valid day of each monthconst correct = Array.from({ length: 4 }, (_, i) => start.add({ months: i }));// 2026-01-31, 2026-02-28, 2026-03-31, 2026-04-30Adding Days Across DST
With a ZonedDateTime, adding a day keeps the same wall-clock time, while adding 24 hours adds exact time:
const before = Temporal.ZonedDateTime.from("2026-03-28T12:00[Europe/Berlin]");
before.add({ days: 1 }).toString(); // 2026-03-29T12:00:00+02:00[Europe/Berlin]before.add({ hours: 24 }).toString(); // 2026-03-29T13:00:00+02:00[Europe/Berlin]A daily reminder at noon should use days. A 24-hour token expiry should use hours.
Differences with until() and since()
const today = Temporal.PlainDate.from("2026-10-27");const launch = Temporal.PlainDate.from("2027-03-15");
today.until(launch).toString(); // "P139D"today.until(launch, { largestUnit: "month" }).toString(); // "P4M16D"today.until(launch, { largestUnit: "year" }).days; // 16
launch.since(today).days; // 139Without largestUnit, PlainDate differences are expressed in days, since months and years vary in length. Ask for bigger units explicitly.
A practical example, calculating someone’s age:
function getAge(birthday, today = Temporal.Now.plainDateISO()) { return birthday.until(today, { largestUnit: "year" }).years;}
getAge(Temporal.PlainDate.from("1990-10-28")); // 35 on 2026-10-27Start and End of Periods
const now = Temporal.Now.zonedDateTimeISO("Europe/Berlin");
now.startOfDay(); // Midnight (or whenever the day starts in that zone)now.with({ day: 1 }).startOfDay(); // Start of the month
const date = now.toPlainDate();const monday = date.subtract({ days: date.dayOfWeek - 1 }); // Start of ISO weekconst sunday = monday.add({ days: 6 }); // End of ISO weekstartOfDay() matters because some time zones skip midnight during DST transitions. Hard-coding with({ hour: 0 }) can land on a time that doesn’t exist.
Durations
Temporal.Duration represents a length of time, in ISO 8601 duration format:
const d1 = Temporal.Duration.from({ hours: 1, minutes: 30 });const d2 = Temporal.Duration.from("PT1H30M");
d1.toString(); // "PT1H30M"d1.hours; // 1d1.minutes; // 30d1.sign; // 1 (or -1, or 0)d1.negated().toString(); // "-PT1H30M"d1.abs();Converting with total()
const d = Temporal.Duration.from({ hours: 2, minutes: 45 });
d.total({ unit: "minute" }); // 165d.total({ unit: "hour" }); // 2.75Balancing with round()
Durations aren’t automatically normalized. 90 minutes stays as 90 minutes until you ask:
const d = Temporal.Duration.from({ minutes: 90 });
d.round({ largestUnit: "hour" }).toString(); // "PT1H30M"Calendar Units Need a Reference
How many days is one month? It depends which month. Any operation that mixes calendar units (years, months, weeks) with fixed units needs relativeTo:
const oneMonth = Temporal.Duration.from({ months: 1 });
oneMonth.total({ unit: "day" }); // RangeErroroneMonth.total({ unit: "day", relativeTo: "2026-02-01" }); // 28oneMonth.total({ unit: "day", relativeTo: "2026-03-01" }); // 31Formatting Durations
Duration.prototype.toLocaleString() uses Intl.DurationFormat:
const d = Temporal.Duration.from({ hours: 1, minutes: 5, seconds: 30 });
d.toLocaleString("en", { style: "long" }); // "1 hour, 5 minutes, 30 seconds"d.toLocaleString("en", { style: "short" }); // "1 hr, 5 min, 30 sec"d.toLocaleString("en", { style: "digital" }); // "1:05:30"d.toLocaleString("de", { style: "long" }); // "1 Stunde, 5 Minuten und 30 Sekunden"Comparing and Sorting
Every type has a static compare() that returns -1, 0, or 1, which plugs straight into Array.prototype.sort:
const dates = ["2026-12-01", "2026-01-15", "2026-07-04"].map((s) => Temporal.PlainDate.from(s),);
dates.sort(Temporal.PlainDate.compare);// [2026-01-15, 2026-07-04, 2026-12-01]Instances have an equals() method:
const a = Temporal.PlainDate.from("2026-10-27");const b = Temporal.PlainDate.from({ year: 2026, month: 10, day: 27 });
a === b; // false (different objects)a.equals(b); // trueRelational Operators Throw
This is the biggest habit to break when coming from Date:
const a = Temporal.PlainDate.from("2026-10-27");const b = Temporal.PlainDate.from("2026-11-01");
a < b; // TypeError: Temporal values can't be compared with < or >Temporal objects deliberately throw from valueOf(). With Date, < works by comparing milliseconds, but for something like PlainDate there’s no single number to compare that would be correct across calendars. Use compare() instead.
ZonedDateTime.equals() is strict: two values representing the same instant in different time zones aren’t equal. To compare moments, compare their instants:
const berlin = Temporal.ZonedDateTime.from("2026-10-27T10:00[Europe/Berlin]");const london = berlin.withTimeZone("Europe/London");
berlin.equals(london); // false (different zones)berlin.toInstant().equals(london.toInstant()); // true (same moment)Temporal.ZonedDateTime.compare(berlin, london); // 0 (compare() only looks at the moment)Rounding
Time values and durations support round() with a unit and rounding mode:
const time = Temporal.PlainTime.from("14:37:52");
time.round({ smallestUnit: "minute" }).toString(); // "14:38:00"time.round({ smallestUnit: "minute", roundingIncrement: 15 }).toString(); // "14:45:00"time.round({ smallestUnit: "hour", roundingMode: "ceil" }).toString(); // "15:00:00"time.round({ smallestUnit: "hour", roundingMode: "floor" }).toString(); // "14:00:00"That roundingIncrement is handy for booking UIs that snap to 15-minute slots:
function nextSlot(now = Temporal.Now.zonedDateTimeISO()) { return now.round({ smallestUnit: "minute", roundingIncrement: 15, roundingMode: "ceil", });}You can also control precision when converting to strings:
const instant = Temporal.Now.instant();
instant.toString(); // "2026-10-27T09:30:00.123456789Z"instant.toString({ smallestUnit: "second" }); // "2026-10-27T09:30:00Z"instant.toString({ fractionalSecondDigits: 3 }); // "2026-10-27T09:30:00.123Z"Formatting for Users
toString() gives you ISO 8601 for machines. For humans, use toLocaleString(), which accepts the same options as Intl.DateTimeFormat:
const meeting = Temporal.ZonedDateTime.from( "2026-11-05T15:00:00[Europe/Berlin]",);
meeting.toLocaleString("en-US");// "11/5/2026, 3:00:00 PM GMT+1"
meeting.toLocaleString("en-GB", { dateStyle: "full", timeStyle: "short",});// "Thursday, 5 November 2026 at 15:00"
Temporal.PlainDate.from("2026-10-27").toLocaleString("de-DE", { weekday: "long", day: "numeric", month: "long",});// "Dienstag, 27. Oktober"A ZonedDateTime formats in its own time zone. Plain types format with no time zone conversion at all, which is exactly why a PlainDate birthday never shifts.
You can also pass Temporal objects directly to an Intl.DateTimeFormat instance, which is faster when formatting many values:
const formatter = new Intl.DateTimeFormat("en-US", { dateStyle: "medium" });
dates.map((date) => formatter.format(date));Relative Time
Combine until() with Intl.RelativeTimeFormat for “in 3 days” labels:
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
function relativeDay(date, today = Temporal.Now.plainDateISO()) { const days = today.until(date).days; return rtf.format(days, "day");}
relativeDay(Temporal.PlainDate.from("2026-10-28")); // "tomorrow"relativeDay(Temporal.PlainDate.from("2026-10-30")); // "in 3 days"relativeDay(Temporal.PlainDate.from("2026-10-24")); // "3 days ago"Serialization and Storage
JSON
Every Temporal type has a toJSON() method that returns its ISO string, so JSON.stringify just works:
const event = { title: "Launch", date: Temporal.PlainDate.from("2027-03-15"), startsAt: Temporal.ZonedDateTime.from("2027-03-15T09:00[America/New_York]"),};
JSON.stringify(event);// {"title":"Launch","date":"2027-03-15","startsAt":"2027-03-15T09:00:00-04:00[America/New_York]"}Parsing back requires knowing which type each field is. A reviver keyed on field names keeps that explicit:
const temporalFields = { date: Temporal.PlainDate, startsAt: Temporal.ZonedDateTime,};
const parsed = JSON.parse(json, (key, value) => temporalFields[key] ? temporalFields[key].from(value) : value,);In a typed codebase, a validation library like Zod at the API boundary is a cleaner place for this conversion.
The Bracketed Time Zone
The [America/New_York] annotation is part of RFC 9557, an extension to the ISO 8601 / RFC 3339 format. Many tools that expect plain RFC 3339 won’t understand it. When sending to such a system, send an Instant string and the zone as a separate field:
const payload = { startsAt: meeting.toInstant().toString(), // "2027-03-15T13:00:00Z" timeZone: meeting.timeZoneId, // "America/New_York"};
// ReconstructTemporal.Instant.from(payload.startsAt).toZonedDateTimeISO(payload.timeZone);Databases
Map each Temporal type to a column that preserves its meaning:
| Temporal type | PostgreSQL column | Notes |
|---|---|---|
Instant | timestamptz | Stored as UTC |
ZonedDateTime | timestamptz + text time zone column | Postgres doesn’t store the zone name |
PlainDate | date | |
PlainTime | time | |
PlainDateTime | timestamp (without time zone) | |
Duration | interval or text (ISO string) | text round-trips exactly |
For future events, consider storing the wall-clock time and zone rather than the instant. If time zone rules change before the event, recomputing from 2027-06-01T10:00 + Europe/Istanbul gives the time the user intended. For past events, the instant is the source of truth. See our guide to PostgreSQL vs MySQL vs SQLite for how each database handles timestamps.
Migrating from Date
You don’t need to rewrite everything at once. Temporal and Date interoperate through epoch milliseconds.
Converting Between Them
// Date → Temporalconst legacy = new Date();const instant = legacy.toTemporalInstant();const zoned = instant.toZonedDateTimeISO(Temporal.Now.timeZoneId());
// Temporal → Dateconst backToDate = new Date(instant.epochMilliseconds);const fromZoned = new Date(zoned.epochMilliseconds);Going back to Date loses the time zone and anything below millisecond precision, so convert at the edges only when a library requires it.
Common Translations
Date / library | Temporal |
|---|---|
Date.now() | Temporal.Now.instant().epochMilliseconds |
new Date() | Temporal.Now.zonedDateTimeISO() |
new Date("2026-10-27") (as a date) | Temporal.PlainDate.from("2026-10-27") |
date.getMonth() + 1 | date.month |
date.getDay() (Sunday = 0) | date.dayOfWeek % 7 (Temporal: Monday = 1, Sunday = 7) |
date.setDate(date.getDate() + 1) | date.add({ days: 1 }) |
date.toISOString() | instant.toString() |
a.getTime() < b.getTime() | Temporal.Instant.compare(a, b) < 0 |
date-fns differenceInDays(b, a) | a.until(b).days |
date-fns startOfMonth(d) | d.with({ day: 1 }) |
date-fns isSameDay(a, b) | a.toPlainDate().equals(b.toPlainDate()) |
Moment moment.tz(str, zone) | Temporal.PlainDateTime.from(str).toZonedDateTime(zone) |
Luxon DateTime.fromISO(s).setZone(z) | Temporal.ZonedDateTime.from(s).withTimeZone(z) |
A Migration Strategy
- Start at the boundaries. Parse incoming API data into Temporal types and convert back to strings on the way out.
- Pick the right type per field. Go through your data model and ask “is this a moment, a calendar date, or a scheduled time?” This is the most valuable part of the migration, and it usually surfaces existing bugs.
- Replace date library calls module by module. Your tests are your safety net here, so run them across multiple time zones (for example
TZ=America/Los_Angeles npm testandTZ=Asia/Kolkata npm test). - Keep
Dateonly where a third-party library demands it, and convert right before the call. - Drop the date library once nothing imports it. Moment.js alone is a large chunk of many bundles.
Browser Support and Polyfills
Temporal shipped in Firefox 139 (2025) and Chrome 144 (early 2026), and is available in other Chromium-based browsers and runtimes built on matching V8 versions. Safari support has been in progress for a while, so check caniuse.com for current status before relying on the native implementation for all your users.
Until support is universal, use a polyfill. There are two main options:
| Polyfill | Notes |
|---|---|
@js-temporal/polyfill | Maintained by the proposal’s champions, closest to spec |
temporal-polyfill | Much smaller bundle, spec-compliant, good for front-ends |
Import explicitly so it’s obvious which implementation you’re using:
import { Temporal } from "temporal-polyfill";Or install it globally only when the native version is missing:
if (typeof globalThis.Temporal === "undefined") { await import("temporal-polyfill/global");}Load that file before the rest of your app, and the polyfill only downloads for browsers that need it.
TypeScript
Recent TypeScript versions include Temporal type definitions in the esnext lib. If your version doesn’t, the polyfill packages ship their own types:
{ "compilerOptions": { "lib": ["ESNext", "DOM"] }}Temporal’s types catch whole categories of bugs at compile time. A function that accepts Temporal.PlainDate can’t be accidentally called with an Instant. For more on modeling domain types precisely, see our guide to advanced TypeScript patterns.
Common Pitfalls
Pitfall 1: Using PlainDateTime as a Moment
// ❌ Which 9:00? This isn't a point in timeconst reminder = Temporal.PlainDateTime.from("2026-11-05T09:00");scheduleJob(reminder);
// ✅ Attach the user's time zoneconst reminder = Temporal.PlainDateTime.from( "2026-11-05T09:00",).toZonedDateTime(user.timeZone);scheduleJob(reminder.toInstant());If you find yourself converting a PlainDateTime with the server’s time zone, it’s almost always a bug. The server’s zone has nothing to do with the user’s intent.
Pitfall 2: Forgetting Immutability
// ❌ Return value discardedconst date = Temporal.PlainDate.from("2026-10-27");date.add({ days: 1 });console.log(date.toString()); // Still 2026-10-27
// ✅ Use the returned valueconst tomorrow = date.add({ days: 1 });Pitfall 3: Comparing with < and >
// ❌ TypeErrorif (deadline < today) { ... }
// ✅if (Temporal.PlainDate.compare(deadline, today) < 0) { ... }Pitfall 4: Reading the Wrong Duration Field
const d = Temporal.PlainDate.from("2026-01-01").until("2026-03-15", { largestUnit: "month",});
d.days; // 14, not 73! The rest is in d.monthsd.total({ unit: "day", relativeTo: "2026-01-01" }); // 73Fields are components, not totals. Use total() when you want a single number.
Pitfall 5: Mixing Temporal Implementations
If one part of your app uses the polyfill’s Temporal and another uses the native global, objects from one may not pass instanceof checks in the other. Pick one approach (explicit import or conditional global) and use it everywhere.
Pitfall 6: Assuming Days Are 24 Hours
// ❌ Wrong on DST transition daysconst tomorrow = zoned.add({ hours: 24 });
// ✅ Calendar dayconst tomorrow = zoned.add({ days: 1 });Best Practices
- Choose the type from the meaning of the data:
Instantfor “when it happened”,ZonedDateTimefor “when it’s scheduled”,PlainDatefor calendar dates - Default to
PlainDatefor dates without times: birthdays, due dates, and holidays shouldn’t carry a time zone - Store the user’s IANA time zone (
Intl.DateTimeFormat().resolvedOptions().timeZone), never a fixed offset like+01:00 - Use
overflow: "reject"when validating input, and the default"constrain"for arithmetic - Add calendar units for human schedules (
days,months) and exact units for technical ones (hours,seconds) - Format with
toLocaleString(), not hand-built strings - Convert to
Dateonly at library boundaries, as late as possible - Test in multiple time zones, including one with a half-hour offset and one in the southern hemisphere
- Pass a fixed “now” into functions instead of calling
Temporal.Nowinside them, so they’re easy to test - Load a polyfill conditionally until Temporal is available in every browser you support
Conclusion
Temporal fixes JavaScript’s longest-running API problem. Instead of one mutable type that pretends every value is a UTC timestamp, it gives you a set of immutable types that match how people actually think about time: moments, calendar dates, wall-clock times, and durations.
Key Takeaways:
- Temporal values are immutable and their months are 1-indexed
- Exact time (
Instant,ZonedDateTime) and wall-clock time (Plain*types) are separate, and Temporal won’t let you mix them up by accident ZonedDateTimehandles DST correctly, withdisambiguationfor gaps and overlaps- Arithmetic is calendar-aware:
add({ days: 1 })andadd({ hours: 24 })mean different things - Use
compare()andequals();<and>throw - Serialize with ISO strings and pick database columns that preserve each type’s meaning
- Migrate at the boundaries first, and use a polyfill until browser support is complete
Most date bugs come from not knowing what kind of value you’re holding. The real benefit of Temporal is that it makes you decide up front. For more on how JavaScript has evolved, see our overview of modern JavaScript features.
Next Steps:
- Open your browser console and try
Temporal.Now.zonedDateTimeISO().toString() - Audit your data model and label each date field as a moment, a calendar date, or a scheduled time
- Add a Temporal polyfill and convert one module that does date arithmetic
- Run your test suite under two or three different
TZvalues
Happy time traveling! ⏰