Replacing Date with Temporal

JavaScript's Date was copied from Java in 1995, and even Java replaced its version long ago. We've all worked around it with Moment, date-fns, Luxon or Day. js.

JavaScript’s Date was copied from Java in 1995, and even Java replaced its version long ago. We’ve all worked around it with Moment, date-fns, Luxon or Day.js. Temporal is the built-in replacement, and this year it became practical: Firefox shipped it in 139, Chrome in 144 in January, and Node 26 turns it on by default.

The bugs Date is famous for

const d = new Date(2026, 0, 31); // January 31 (months start at 0)
d.setMonth(d.getMonth() + 1);
d.toDateString(); // 'Tue Mar 03 2026'

January 31 plus one month is March 3, because February 31 doesn’t exist and Date silently rolls over. And setMonth changed d in place, so anything else holding that object changed too.

Parsing is just as fun. new Date(‘2026-03-08’) is read as midnight UTC, but new Date(‘2026-03-08T00:00’) is read as midnight local time. Same day, different moments, depending on whether the string has a time in it.

Temporal has a type for each job

Instead of one Date that tries to be everything, Temporal has separate types:

Type Represents Example
Temporal.PlainDate a calendar date, no time or zone a birthday, a due date
Temporal.PlainTime a wall-clock time opening hours
Temporal.PlainDateTime date and time, no zone a form field before you know the zone
Temporal.ZonedDateTime a moment in a specific time zone a meeting at 9:00 in New York
Temporal.Instant an exact moment, no zone a log timestamp
Temporal.Duration a length of time 2 hours 30 minutes

Picking the right type is most of the work, and it prevents a whole class of bugs. A birthday stored as a PlainDate can’t shift by a day when someone opens the app in another time zone.

Date math that does what you mean

const due = Temporal.PlainDate.from('2026-01-31');

due.add({ months: 1 }).toString(); // '2026-02-28'
due.toString();                    // '2026-01-31', unchanged

It clamps to the end of February instead of rolling over, and every operation returns a new object. If you’d rather get an error than a clamped date, pass { overflow: ‘reject’ }.

Time zones and daylight saving time finally behave:

const meeting = Temporal.ZonedDateTime.from('2026-03-07T09:00[America/New_York]');

meeting.add({ days: 1 }).toString();
// '2026-03-08T09:00:00-04:00[America/New_York]'

meeting.add({ hours: 24 }).toString();
// '2026-03-08T10:00:00-04:00[America/New_York]'

US clocks jump forward on March 8, 2026. “One day later” keeps the meeting at 9:00. “24 hours later” is 10:00 local time. Both are correct answers to different questions, and Temporal makes you pick. With Date, the usual + 24 * 60 * 60 * 1000 silently gave you the second one.

Converting between zones is a single call:

meeting.add({ days: 1 }).withTimeZone('Asia/Kolkata').toString();
// '2026-03-08T18:30:00+05:30[Asia/Kolkata]'

Differences and durations

const start = Temporal.PlainDate.from('2026-02-10');
const end = Temporal.PlainDate.from('2026-12-25');

start.until(end, { largestUnit: 'months' }).toString(); // 'P10M15D'
end.since(start).days;                                  // 318

Temporal.Duration.from({ hours: 1, minutes: 90 })
  .round({ largestUnit: 'hours' })
  .toString(); // 'PT2H30M'

The P10M15D format is ISO 8601: 10 months, 15 days. Durations also have .total({ unit: ‘minutes’ }) when you need one number.

Comparing

You can’t compare Temporal objects with < or >. It throws, on purpose:

TypeError: Do not use Temporal.PlainDate.prototype.valueOf;
use Temporal.PlainDate.prototype.compare for comparison.

Use equals() or the static compare(), which also works as a sort function:

start.equals(Temporal.PlainDate.from('2026-02-10')); // true
dates.sort(Temporal.PlainDate.compare);

Working with existing Date code

You won’t replace every Date at once. Converting at the edges is easy:

const instant = legacyDate.toTemporalInstant();
const backToDate = new Date(instant.epochMilliseconds);

For APIs and databases, use the string forms. toString() and JSON.stringify give ISO strings, and a ZonedDateTime includes its zone name:

JSON.stringify({ when: Temporal.ZonedDateTime.from('2026-08-14T18:30[Europe/London]') });
// '{"when":"2026-08-14T18:30:00+01:00[Europe/London]"}'

For display, toLocaleString takes the same options as Intl.DateTimeFormat.

Can you use it today?

  • Node: yes, in Node 26 without a flag. Not in Node 24.
  • Browsers: Chrome, Edge and Firefox, yes. Safari doesn’t ship it yet, so for frontend code you still need a polyfill such as temporal-polyfill or @js-temporal/polyfill.
  • TypeScript: 6.0 includes the types with “lib”: [“esnext”].

On the server, I’d start using it now for new code, especially anything with time zones or calendar math. In the browser, the polyfill adds some bundle size, so whether it’s worth it depends on how much date logic your frontend has. Either way, new code written against Temporal won’t need to change when Safari catches up. You’ll just remove the polyfill.