NewNode 26.14: mockResolvedValue and Friends in node:test →
w3/w3-tutorials

Node.js 26 LTS: Migrate from Date to Temporal

Node.js 26 is LTS and ships Temporal switched on. Replace Date for parsing, time zones, DST, durations and Postgres timestamps, and avoid the traps that break old code.

Updated Nov 12, 20268 min readIntermediatenode 26.13.1 · typescript 7.0.2 · pg 8.23.1 · postgres 18.6

Node.js 26 became LTS on 28 October 2026, and it ships the Temporal API switched on. No flag, no polyfill. If your team upgrades from Node 22 or 24 this winter, you can finally stop fighting Date.

This guide walks through the swaps you will actually make: getting the current time, parsing, time zones and daylight saving, month arithmetic, durations, formatting, and reading timestamps from Postgres. Every example ran on Node 26.13.1.

1. Check that Temporal is there

terminal
node -e "console.log(process.version, typeof Temporal)"
text
v26.13.1 object

If you see undefined, you are on an older Node. The Node 26.0.0 release notes list Temporal as enabled by default, and the 26.13.0 LTS announcement gives support until the end of April 2029.

2. Pick the right type

Date is one type that tries to be everything. Temporal splits the job, and picking the right type is most of the migration:

You haveUseExample
An exact moment (logs, created_at)Temporal.Instant2026-11-12T15:23:20Z
A moment people see in a placeTemporal.ZonedDateTime2026-11-12T17:23+02:00[Europe/Athens]
A calendar date (birthday, due date)Temporal.PlainDate2026-12-01
A wall-clock time with no zoneTemporal.PlainDateTime2026-03-29T01:30
A length of timeTemporal.DurationPT2H15M

Ask one question: does this value point to a single moment on Earth? If yes, it is an Instant or a ZonedDateTime. If it is "1 December" for everyone, it is a PlainDate. Storing a due date as a Date is how invoices end up a day early for customers west of you.

3. Get the current time

Date.now() and new Date() become Temporal.Now:

now.mjs
const instant = Temporal.Now.instant();
const athens = Temporal.Now.zonedDateTimeISO('Europe/Athens');
const today = Temporal.Now.plainDateISO('Europe/Athens');

console.log(instant.toString());
console.log(athens.toString());
console.log(today.toString());
console.log(instant.epochMilliseconds);
text
2026-11-12T15:25:41.002897949Z
2026-11-12T17:25:41.006552002+02:00[Europe/Athens]
2026-11-12
1794497141002

Two things to notice. Temporal has nanosecond precision, and "today" needs a time zone, because it is already tomorrow somewhere. Passing the zone explicitly makes server code behave the same whatever TZ the container runs with.

4. Parse strictly

Date parsing guesses, and it guesses differently depending on the string. Run this with TZ=Europe/Athens:

parse-date.mjs
console.log(new Date('2026-03-29').toISOString());
console.log(new Date('2026-03-29T10:00').toISOString());
console.log(new Date('2026-02-31T10:00').toISOString());
text
2026-03-29T00:00:00.000Z
2026-03-29T07:00:00.000Z
2026-03-03T08:00:00.000Z

A date-only string is read as UTC, but the same string with a time is read as local time. And 31 February silently becomes 3 March. Temporal refuses to guess:

parse-temporal.mjs
const show = (fn) => {
  try {
    console.log(fn().toString());
  } catch (err) {
    console.log(`${err.name}: ${err.message}`);
  }
};

show(() => Temporal.PlainDate.from('2026-03-29'));
show(() => Temporal.PlainDate.from('2026-02-31'));
show(() => Temporal.Instant.from('2026-03-29T10:00'));
show(() => Temporal.Instant.from('2026-03-29T10:00+03:00'));
text
2026-03-29
RangeError: Temporal error: Parsed day value not in a valid range.
RangeError: Temporal error: Required fields missing from Instant string.
2026-03-29T07:00:00Z

An Instant needs an offset or Z, so a timestamp with no zone fails loudly instead of being read in whatever zone the server happens to use. Wrap parsing of user input in try/catch and return a 400.

5. Time zones and daylight saving

Clocks in the UK went forward on 29 March 2026. Here is "same time tomorrow" across that change, run with TZ=Europe/London:

dst.mjs
// Date: "tomorrow" by adding 24 hours of milliseconds
const start = new Date('2026-03-28T09:00'); // local time in Europe/London
const next = new Date(start.getTime() + 24 * 60 * 60 * 1000);
console.log(next.toString());

// Temporal: say whether you mean a calendar day or 24 hours
const meeting = Temporal.ZonedDateTime.from('2026-03-28T09:00[Europe/London]');
console.log(meeting.add({ days: 1 }).toString());
console.log(meeting.add({ hours: 24 }).toString());
text
Sun Mar 29 2026 10:00:00 GMT+0100 (British Summer Time)
2026-03-29T09:00:00+01:00[Europe/London]
2026-03-29T10:00:00+01:00[Europe/London]

The 9:00 meeting moved to 10:00 with Date. With ZonedDateTime, days: 1 keeps the wall-clock time and hours: 24 keeps the exact elapsed time. You pick the meaning, and the code says which one.

Some local times don't exist at all. 01:30 on 29 March was skipped in London:

gap.mjs
const wall = Temporal.PlainDateTime.from('2026-03-29T01:30');

console.log(wall.toZonedDateTime('Europe/London').toString());

try {
  wall.toZonedDateTime('Europe/London', { disambiguation: 'reject' });
} catch (err) {
  console.log(`${err.name}: ${err.message}`);
}
text
2026-03-29T02:30:00+01:00[Europe/London]
RangeError: Temporal error: Rejecting ambiguous time zones.

The default (compatible) shifts forward, like Date does. Use disambiguation: 'reject' for things like scheduling forms, where asking the user is better than moving their booking.

6. Month arithmetic

months.mjs
const d = new Date(2026, 0, 31);
d.setMonth(d.getMonth() + 1);
console.log(d.toDateString());

const jan31 = Temporal.PlainDate.from('2026-01-31');
console.log(jan31.add({ months: 1 }).toString());

try {
  jan31.add({ months: 1 }, { overflow: 'reject' });
} catch (err) {
  console.log(`${err.name}: ${err.message}`);
}
text
Tue Mar 03 2026
2026-02-28
RangeError: Temporal error: not a valid ISO date.

"One month after 31 January" with Date is 3 March. Temporal clamps to the end of February, which is what billing code usually wants, or throws if you ask it to. Temporal objects are also immutable: add() returns a new value, so there is no setMonth() changing a date another function still holds.

7. Durations and comparisons

Replace "subtract milliseconds and divide by 86,400,000":

durations.mjs
const today = Temporal.PlainDate.from('2026-11-12');
const launch = Temporal.PlainDate.from('2027-02-01');

console.log(today.until(launch).toString());
console.log(today.until(launch, { largestUnit: 'month' }).toString());
console.log(today.until(launch).days);

const call = Temporal.Duration.from({ minutes: 135 });
console.log(call.round({ largestUnit: 'hour' }).toString());
console.log(call.total('hours'));
text
P81D
P2M20D
81
PT2H15M
2.25

Comparisons are the one place old habits break loudly:

compare.mjs
const a = Temporal.PlainDate.from('2026-11-12');
const b = Temporal.PlainDate.from('2026-11-12');

console.log(a === b);
console.log(a.equals(b));

const dates = ['2027-01-05', '2026-12-24', '2026-11-30'].map((s) => Temporal.PlainDate.from(s));
dates.sort(Temporal.PlainDate.compare);
console.log(dates.map(String));

try {
  console.log(a < b);
} catch (err) {
  console.log(`${err.name}: ${err.message}`);
}
text
false
true
[ '2026-11-30', '2026-12-24', '2027-01-05' ]
TypeError: Do not use Temporal.PlainDate.prototype.valueOf; use Temporal.PlainDate.prototype.compare for comparison.

< and > throw a TypeError on purpose. Search your codebase for date comparisons with operators and switch them to compare() or equals() before you swap the types.

8. Formatting

format.mjs
const at = Temporal.ZonedDateTime.from('2026-11-12T15:23[Europe/Athens]');

console.log(at.toString());
console.log(at.toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }));
console.log(at.toPlainDate().toLocaleString('de-DE', { dateStyle: 'full' }));
console.log(at.withTimeZone('America/New_York').toString());
text
2026-11-12T15:23:00+02:00[Europe/Athens]
12 Nov 2026, 15:23
Donnerstag, 12. November 2026
2026-11-12T08:23:00-05:00[America/New_York]

toLocaleString() takes the same Intl.DateTimeFormat options as Date.prototype.toLocaleString(), so existing formatting calls carry over.

9. Interop with Date and JSON

You will live with both types for a while. Libraries, ORMs and many APIs still hand you Date objects:

interop.mjs
// Date -> Temporal
const legacy = new Date('2026-11-12T15:23:20.123Z');
const instant = legacy.toTemporalInstant();
console.log(instant.toString());

// Temporal -> Date, for libraries that still want one
const back = new Date(instant.epochMilliseconds);
console.log(back.toISOString());

// JSON: Temporal values serialize as ISO strings
const json = JSON.stringify({ at: instant, due: Temporal.PlainDate.from('2026-12-01') });
console.log(json);

// ...but parsing gives you strings back, so convert explicitly
const parsed = JSON.parse(json);
const due = Temporal.PlainDate.from(parsed.due);
console.log(typeof parsed.at, due.add({ days: 7 }).toString());
text
2026-11-12T15:23:20.123Z
2026-11-12T15:23:20.123Z
{"at":"2026-11-12T15:23:20.123Z","due":"2026-12-01"}
string 2026-12-08

Converting to Date drops anything below milliseconds. Converting back from JSON is your job: parse and validate the strings at the edge of your API, then pass Temporal values inward.

10. Postgres timestamps

The pg driver turns timestamptz and date into Date by default. Run with TZ=Europe/Athens:

pg-default.mjs
import pg from 'pg';

const client = new pg.Client(process.env.DATABASE_URL);
await client.connect();

const { rows } = await client.query(
  `select timestamptz '2026-11-12 15:23:20.123456+00' as at, date '2026-12-01' as due`,
);
console.log(rows[0]);

await client.end();
text
{ at: 2026-11-12T15:23:20.123Z, due: 2026-11-30T22:00:00.000Z }

The microseconds are gone, and the date 2026-12-01 came back as 30 November in UTC, because it was read as local midnight. Tell pg to build Temporal values instead:

db.mjs
import pg from 'pg';

const { types } = pg;

// Parse Postgres text output into Temporal types instead of Date
types.setTypeParser(types.builtins.TIMESTAMPTZ, (s) => Temporal.Instant.from(s));
types.setTypeParser(types.builtins.TIMESTAMP, (s) => Temporal.PlainDateTime.from(s));
types.setTypeParser(types.builtins.DATE, (s) => Temporal.PlainDate.from(s));

export const client = new pg.Client(process.env.DATABASE_URL);
pg-temporal.mjs
import { client } from './db.mjs';

await client.connect();
await client.query('begin');

await client.query(`create table events (id int, starts_at timestamptz, day date)`);

// Write: pass the ISO string
const startsAt = Temporal.ZonedDateTime.from('2026-11-12T17:23:20.123456[Europe/Athens]');
await client.query('insert into events values ($1, $2, $3)', [
  1,
  startsAt.toInstant().toString(),
  startsAt.toPlainDate().toString(),
]);

// Read: Temporal objects, microseconds intact
const { rows } = await client.query('select starts_at, day from events');
const row = rows[0];
console.log(row.starts_at.constructor.name, row.starts_at.toString());
console.log(row.day.constructor.name, row.day.toString());
console.log(row.starts_at.toZonedDateTimeISO('Europe/Athens').toString());

await client.query('rollback');
await client.end();
text
Instant 2026-11-12T15:23:20.123456Z
PlainDate 2026-11-12
2026-11-12T17:23:20.123456+02:00[Europe/Athens]

Postgres stores microseconds and Temporal keeps them, so values now round-trip exactly. Temporal.Instant.from() accepts the space separator and short +00 offset that Postgres prints. The type parsers are global for the process, so set them once at startup, and check that your ORM isn't installing its own. See the node-postgres types docs for the full list of type IDs.

TypeScript

TypeScript ships the types, but not in older lib settings. With "lib": ["es2024"] you get Cannot find namespace 'Temporal'. Add the Temporal lib:

tsconfig.json
{
  "compilerOptions": {
    "target": "es2024",
    "lib": ["es2024", "esnext.temporal"],
    "module": "nodenext",
    "strict": true,
    "noEmit": true,
    "types": ["node"]
  }
}

Using "lib": ["esnext"] also works. This was checked with TypeScript 7.0.2.

When to keep Date

  • Browser code. MDN still marks Temporal as limited availability across browsers. Check the compatibility table before shipping it to the front end, or send ISO strings and parse on each side.
  • Library boundaries. If an ORM or SDK returns Date, convert at the boundary rather than fighting its types. Rewriting a working module just to swap types is churn.
  • Hot paths that only need a number. Date.now() is fine for measuring elapsed milliseconds. For precise timing, performance.now() was always the better tool anyway.

Next steps

Related tutorials