toISOString
Stable UTC string for storage, logs and APIs.
Date formatting turns a time value into text. Use ISO for machines and Intl for people.
const date = new Date("2026-01-01T09:30:00Z");
date.toISOString();
date.toLocaleDateString("en-GB");
Dates, Time & Intl
A stored date should be stable and unambiguous. ISO strings and timestamps are good storage or transport formats because they do not depend on visual language.
A displayed date should match the user, locale and context. Intl.DateTimeFormat and toLocaleDateString can show dates in a readable regional format.
Manual formatting is tempting, but it is easy to get separators, leading zeros, month names, time zones and languages wrong.
Stable UTC string for storage, logs and APIs.
Locale-aware date display.
Reusable formatter with explicit locale and options.
Only safe when the exact format is simple and controlled.
Examples
const stored = "2026-01-01T09:30:00Z";
const date = new Date(stored);
const visible = new Intl.DateTimeFormat("en-GB", {
dateStyle: "long",
timeStyle: "short"
}).format(date);
const visible = "01/02/2026"; // Is this 1 February or January 2?
Code patterns
Dates and time zones become much easier when every example names the concept it represents: instant, local display, UTC output, calendar date, formatted text or zoned time.
Use ISO when another system must read the date.
const date = new Date("2026-01-01T09:30:00Z");
console.log(date.toISOString());
Use locale formatting for human display.
const date = new Date("2026-01-01T09:30:00Z");
console.log(date.toLocaleDateString("en-GB"));
Intl can show readable date parts.
const formatter = new Intl.DateTimeFormat("en-GB", {
dateStyle: "long"
});
console.log(formatter.format(new Date("2026-01-01T09:30:00Z")));
Include time when the time of day matters.
const formatter = new Intl.DateTimeFormat("en-GB", {
dateStyle: "medium",
timeStyle: "short",
timeZone: "UTC"
});
console.log(formatter.format(new Date("2026-01-01T09:30:00Z")));
Rules that matter
Date-time bugs usually start when storage format, calculation logic and user-facing display are treated as the same thing. Keep those responsibilities separate and the code becomes much easier to trust.
APIs, logs and databases need unambiguous values.
People expect dates in a familiar language and order.
A time without zone context can mislead users.
01/02/2026 can mean different dates.
Creating an Intl formatter once is cleaner than repeating options.
Display strings are for people, not data recovery.
Production thinking
The same date can be correct for a machine and confusing for a person. Formatting is the boundary between those two worlds.
Readable date text should include enough context. Screen reader users should not have to guess date order.
Production applications should define storage format, transport format and display format separately.
Use machine-readable dates for metadata and readable dates for visible content.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Dates are full of traps. Explain the concept first, then run the code and check whether the output matches your mental model.