---
title: "Dates done right with the Temporal API"
description: "A practical guide to Temporal, the modern JavaScript date and time API: PlainDate, ZonedDateTime, Instant and Duration, how they compare with Date, and how to use them today."
url: https://www.danny.engineering/article/dates-done-right-with-the-temporal-api
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:25:00.000Z
tags: ["Javascript"]
---

# Dates done right with the Temporal API

If you have worked with dates in JavaScript, you have probably been caught out by `Date`. Months start at zero. Objects are mutable, so passing a date into a function can change it behind your back. Parsing strings behaves differently depending on the format. There is no proper time zone support beyond the user's local zone and UTC. Adding a month or working out the number of days between two dates means writing your own maths, or installing a library like date-fns, Luxon or Day.js.


Temporal is the replacement. It is a new global object, built into the language, with separate types for the different things people mean when they say "a date": a calendar date, a wall-clock time, an exact moment, or a length of time. It reached Stage 4 at TC39 in March 2026, which means it is part of the ECMAScript standard.


This article is for JavaScript developers who want to understand Temporal's main types, when to use each one, and how to adopt it today, including in browsers that do not have it yet.


## The core idea: pick the right type


`Date` tries to be everything at once. Under the hood it is just a count of milliseconds since 1 January 1970 UTC, and every method converts that number to your local time zone on the fly. That is why a birthday stored as a `Date` can show up as the day before for someone in another country.


Temporal splits this into types that each carry exactly the information they need:


| Type                     | What it represents                      | Example                                     |
| ------------------------ | --------------------------------------- | ------------------------------------------- |
| `Temporal.PlainDate`     | A calendar date, no time or zone        | A birthday, a public holiday                |
| `Temporal.PlainTime`     | A wall-clock time, no date or zone      | Opening time: 09:00                         |
| `Temporal.PlainDateTime` | A date and time, no zone                | A local event time before you know the zone |
| `Temporal.ZonedDateTime` | A date and time in a specific time zone | A meeting at 10:00 in London                |
| `Temporal.Instant`       | An exact moment on the global timeline  | A log timestamp                             |
| `Temporal.Duration`      | A length of time                        | 1 hour 30 minutes                           |


There are also `Temporal.PlainYearMonth` and `Temporal.PlainMonthDay` for things like "November 2026" or "25 December", and `Temporal.Now` for getting the current time.


Two rules apply to every type:

- **They are immutable.** Methods like `add()` return a new object instead of changing the original.
- **Months are numbered from 1.** January is 1, December is 12.

## PlainDate: calendar dates without time zone bugs


Use `PlainDate` whenever the time of day does not matter.


```javascript
const birthday = Temporal.PlainDate.from('1990-06-15');

birthday.year;      // 1990
birthday.month;     // 6
birthday.day;       // 15
birthday.dayOfWeek; // 5 (Monday is 1, Sunday is 7)

const today = Temporal.Now.plainDateISO();
```


You can also build one from parts:


```javascript
const launch = Temporal.PlainDate.from({ year: 2026, month: 11, day: 27 });
launch.toString(); // '2026-11-27'
```


### Doing arithmetic


Adding days, weeks, months or years is built in:


```javascript
const start = Temporal.PlainDate.from('2026-01-31');

start.add({ days: 1 }).toString();    // '2026-02-01'
start.add({ months: 1 }).toString();  // '2026-02-28'
start.subtract({ years: 1 }).toString(); // '2025-01-31'
```


Notice that adding one month to 31 January gives 28 February, not 3 March. By default Temporal constrains the result to the last valid day of the month. If you would rather get an error, pass `{ overflow: 'reject' }` as a second argument.


To change one field, use `with()`:


```javascript
const firstOfMonth = start.with({ day: 1 }); // 2026-01-01
```


### Working out the difference


`until()` and `since()` return a `Duration`:


```javascript
const today = Temporal.PlainDate.from('2026-11-27');
const christmas = Temporal.PlainDate.from('2026-12-25');

today.until(christmas).days; // 28

const age = Temporal.PlainDate.from('1990-06-15')
  .until(today, { largestUnit: 'year' });

age.years; // 36
```


The `largestUnit` option controls how the result is broken down. Without it, `PlainDate` differences are expressed in days.


## ZonedDateTime: real-world times in real time zones


`ZonedDateTime` is the type to reach for when you are dealing with something that happens at a particular time in a particular place. It knows its IANA time zone, such as `Europe/London` or `America/New_York`, and it handles daylight saving time for you.


```javascript
const meeting = Temporal.ZonedDateTime.from(
  '2026-11-30T10:00[Europe/London]'
);

meeting.toString();
// '2026-11-30T10:00:00+00:00[Europe/London]'
```


Converting to another zone is one method call:


```javascript
const inNewYork = meeting.withTimeZone('America/New_York');
inNewYork.hour; // 5
```


To get the current time in the user's zone:


```javascript
const now = Temporal.Now.zonedDateTimeISO();
now.timeZoneId; // for example 'Europe/London'
```


### Daylight saving time, handled


In the UK, clocks go forward at 01:00 on 29 March 2026. That day is only 23 hours long. Watch what happens when you add a day compared with adding 24 hours:


```javascript
const before = Temporal.ZonedDateTime.from(
  '2026-03-28T12:00[Europe/London]'
);

before.add({ days: 1 }).toString();
// '2026-03-29T12:00:00+01:00[Europe/London]'

before.add({ hours: 24 }).toString();
// '2026-03-29T13:00:00+01:00[Europe/London]'
```


Adding a day keeps the same wall-clock time, which is what you want for "same time tomorrow". Adding 24 hours adds exactly 24 real hours. With `Date`, you would have to know about this and handle it yourself.


## Instant: exact moments for machines


`Instant` is a point on the global timeline with no time zone or calendar attached. It is the closest thing in Temporal to what `Date` actually stores, but with nanosecond precision.


Use it for timestamps: logs, database records, API responses, measuring when something happened.


```javascript
const now = Temporal.Now.instant();
now.toString(); // '2026-11-27T14:03:12.123456789Z'

const created = Temporal.Instant.from('2026-11-27T09:00:00Z');
now.since(created).toString(); // for example 'PT18192.123456789S'
```


When you need to show an instant to a person, convert it to a zoned value first:


```javascript
const local = created.toZonedDateTimeISO('Europe/London');
local.toLocaleString('en-GB', { dateStyle: 'full', timeStyle: 'short' });
// 'Friday 27 November 2026 at 09:00'
```


A good rule: store and send `Instant` values (as ISO strings with a `Z`), and convert to `ZonedDateTime` at the edge, when displaying to a user.


## Duration: lengths of time


`Duration` represents an amount of time, such as "2 hours 30 minutes" or "1 year 2 months". You get one from `until()` and `since()`, or create one directly:


```javascript
const film = Temporal.Duration.from({ hours: 2, minutes: 15 });

film.toString();                     // 'PT2H15M'
film.total({ unit: 'minutes' });     // 135

const longer = film.add({ minutes: 50 });
longer.round({ largestUnit: 'hour' }).toString(); // 'PT3H5M'
```


Durations also format nicely for display with `toLocaleString()`, in environments that support `Intl.DurationFormat`:


```javascript
film.toLocaleString('en-GB', { style: 'long' });
// '2 hours, 15 minutes'
```


One subtlety: durations containing years, months or weeks do not have a fixed length. A month might be 28 or 31 days. Methods that need to know the real length, such as `total()` or `Duration.compare()` on calendar units, require a `relativeTo` option telling Temporal which date to measure from:


```javascript
const oneMonth = Temporal.Duration.from({ months: 1 });

oneMonth.total({
  unit: 'days',
  relativeTo: Temporal.PlainDate.from('2026-02-01'),
}); // 28
```


## Comparing values


This is a place where Temporal deliberately differs from `Date`. With `Date`, you can write `a < b` because the object quietly converts to a number. Temporal objects throw a `TypeError` if you try that, to stop you from accidentally comparing values that do not mean the same thing.


Use `equals()` for equality and the static `compare()` for ordering:


```javascript
const a = Temporal.PlainDate.from('2026-11-27');
const b = Temporal.PlainDate.from('2026-12-25');

a.equals(b);                     // false
Temporal.PlainDate.compare(a, b); // -1

const dates = [b, a];
dates.sort(Temporal.PlainDate.compare); // [a, b]
```


`compare()` returns -1, 0 or 1, which is exactly the shape `Array.prototype.sort()` wants.


## Temporal compared with Date


Here are some common tasks side by side.


Getting tomorrow's date:


```javascript
// Date
const d = new Date();
d.setDate(d.getDate() + 1); // mutates d

// Temporal
const tomorrow = Temporal.Now.plainDateISO().add({ days: 1 });
```


Creating 1 March 2026:


```javascript
// Date: month index 2 means March
new Date(2026, 2, 1);

// Temporal: month 3 means March
Temporal.PlainDate.from({ year: 2026, month: 3, day: 1 });
```


Showing a time in another zone:


```javascript
// Date: only possible through formatting
new Date().toLocaleString('en-GB', { timeZone: 'Asia/Tokyo' });

// Temporal: a real value you can keep working with
Temporal.Now.zonedDateTimeISO('Asia/Tokyo').add({ hours: 2 });
```


### Moving between the two


You will be working alongside `Date` for a long time, especially with older libraries. Conversion is straightforward through `Instant`:


```javascript
// Date to Temporal
const legacy = new Date();
const instant = legacy.toTemporalInstant();
// or: Temporal.Instant.fromEpochMilliseconds(legacy.getTime())

// Temporal to Date
const back = new Date(instant.epochMilliseconds);
```


### Serialising to JSON


Temporal objects turn into ISO 8601 strings with `JSON.stringify()`. When reading JSON back, you get strings, so parse them with the matching `from()` method:


```javascript
const payload = JSON.stringify({ due: Temporal.PlainDate.from('2026-12-01') });
// '{"due":"2026-12-01"}'

const { due } = JSON.parse(payload);
const dueDate = Temporal.PlainDate.from(due);
```


## Using Temporal in TypeScript


Recent versions of TypeScript include type definitions for Temporal under the newer `lib` options. If your setup does not recognise the global yet, the polyfill packages below ship their own types, and you can import `Temporal` from them directly.


## Version support


At the time of writing (late 2026):

- **Firefox** has shipped Temporal since version 139, released in 2025.
- **Chrome and Edge** shipped it in version 144, in January 2026.
- **Node.js** includes it from Node.js 26.
- **Safari** does not support it in a stable release yet. Work is under way in WebKit, but you should not assume it is there.

Because Safari is the default on every iPhone, you cannot use the global `Temporal` unguarded on a public website yet. There are two well-maintained polyfills:

- `@js-temporal/polyfill`, from the champions of the proposal.
- `temporal-polyfill`, a smaller alternative.

You can import from a polyfill directly, which works everywhere:


```bash
npm install @js-temporal/polyfill
```


```javascript
import { Temporal } from '@js-temporal/polyfill';

const today = Temporal.Now.plainDateISO();
```


Or use the native object when it exists and load the polyfill only when it does not:


```javascript
async function getTemporal() {
  if (globalThis.Temporal) return globalThis.Temporal;
  const { Temporal } = await import('@js-temporal/polyfill');
  return Temporal;
}
```


Polyfills add weight to your bundle, so check the current size before you add one, and plan to remove it once your supported browsers all ship Temporal natively. Check caniuse for the latest support data.


## When not to use it

- **Simple timestamps in performance code.** For measuring how long something took, `performance.now()` is lighter and more precise for that job.
- **When a polyfill is too heavy.** On a small page that only formats one date, `Intl.DateTimeFormat` with a plain `Date` may be enough, and avoids shipping a polyfill to Safari users.
- **Mixing types carelessly.** Temporal will not let you add a `PlainDate` to a `ZonedDateTime` without being explicit. If your code needs lots of conversions, step back and decide which type the data should really be.
- **Libraries that expect Date.** Many date pickers, ORMs and charting libraries still take `Date` objects. Convert at the boundary rather than fighting them.

## Wrapping up

- Choose the type that matches your data: `PlainDate` for calendar dates, `ZonedDateTime` for real-world times in a place, `Instant` for exact timestamps and `Duration` for lengths of time.
- Temporal objects are immutable and months start at 1, removing two of the biggest sources of `Date` bugs.
- Compare values with `equals()` and `compare()`, never with the less-than or greater-than operators.
- Time zone and daylight saving maths are built in, so adding a day and adding 24 hours now mean different, correct things.
- Firefox, Chrome, Edge and Node.js have Temporal natively; use a polyfill for Safari until it ships there.

## Related reading

- [MDN: Temporal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal)
- [MDN: Temporal.ZonedDateTime](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime)
