Formatting dates in ECMAScript
How ECMAScript date formatting works: what Date.UTC returns, which string methods have fixed formats, and when locale output is safe to copy, share or parse.
Formatting a date in ECMAScript means turning a stored moment in time into a string a person or program can read. The built-in options produce very different kinds of string. Some follow a fixed, specified layout. Others depend on the user's locale, time zone and the engine's locale data. This review covers what each approach changes, where the output stays reliable after it is copied or shared, and when a plain machine-readable string is the better choice.
Short answer: which format suits which use
For data that will be stored, exchanged between systems or parsed again, use toISOString(). It always produces the same UTC layout, and Date.parse is required to read it back. For text that people will read, use Intl.DateTimeFormat or toLocaleString() with an explicit locale and time zone. The main benefit is natural, localized wording. The tradeoff is that the exact output is not fixed: punctuation, spacing, word order and invisible characters can vary between locales and engine versions. Never parse localized output or compare it as a string. A human-readable string is not enough on its own whenever the value must be searched, sorted, edited or processed, so pair it with an ISO string.
| Method | Time zone used | Output format | Suitable for |
| toISOString() | Always UTC | Fixed: YYYY-MM-DDTHH:mm:ss.sssZ | Storage, APIs, logs, round-tripping |
| toJSON() | Always UTC | Same as toISOString() | JSON serialization |
| toUTCString() | Always UTC | Fixed English layout ending in GMT | HTTP-style headers, simple UTC display |
| toString(), toDateString(), toTimeString() | Local | Fixed English layout; time zone name is implementation-defined | Debugging |
| toLocaleString(), Intl.DateTimeFormat | Local or a chosen timeZone | Locale-dependent, not fixed | Display to people |
What "Date.UTC format" actually refers to
Searches for a "Date.UTC format" often mix up two separate things. Date.UTC is a static method that builds a value. It does not format anything. It takes year, month index, day, hours, minutes, seconds and milliseconds, interprets them as UTC, and returns a number: the milliseconds since 1970-01-01T00:00:00Z. The month index is zero-based, so 0 means January. Years from 0 to 99 are mapped to 1900–1999. The returned number can be passed to new Date() to get a Date object. Only after that do the formatting methods come into play.
const ms = Date.UTC(2030, 0, 15, 9, 30);
// 1894699800000 (a number, not a string)
const d = new Date(ms);
d.toISOString(); // "2030-01-15T09:30:00.000Z"
d.toUTCString(); // "Tue, 15 Jan 2030 09:30:00 GMT"
The two outputs above have layouts fixed by the specification, so they are the same in every conforming engine. toISOString() throws a RangeError for an invalid date. For years outside 0000–9999 it uses a six-digit year with a sign, such as +012345.
What formatting changes and what it leaves alone
A Date object stores a single number, the time value. It has no internal time zone, locale or display format. Every formatting method reads that number and produces a new string. The stored value never changes. What differs between methods is the presentation: which time zone the number is converted to, which calendar fields are shown, and which language and punctuation surround them. This is why the same Date can print as January 14 in one place and January 15 in another. The moment is the same; only the local wall-clock rendering differs.
A common example is a date-only string. new Date('2030-01-15') is read as midnight UTC. When it is displayed with toString() or toLocaleString() in a US time zone, it appears as the evening of January 14. A date-time string without an offset, such as '2030-01-15T09:30', is read as local time instead. Date.parse is only guaranteed to accept the specification's ISO-based format. Other inputs, including localized strings, are handled in an implementation-specific way and should not be relied on.
const d = new Date(Date.UTC(2030, 0, 15, 9, 30));
new Intl.DateTimeFormat('en-US', {
timeZone: 'UTC',
dateStyle: 'medium',
timeStyle: 'short'
}).format(d);
// typically "Jan 15, 2030, 9:30 AM"
new Intl.DateTimeFormat('en-GB', {
timeZone: 'UTC',
dateStyle: 'medium',
timeStyle: 'short'
}).format(d);
// typically "15 Jan 2030, 09:30"
The Intl outputs above are marked "typically" for a reason. The specification leaves the exact text of locale-sensitive formatting to the implementation, which takes it from locale data such as CLDR. That data is updated over time. Passing timeZone: 'UTC' makes the result independent of the reader's location. Without it, the result uses the runtime's local time zone.
Will the result stay readable after copying or sharing?
ISO and UTC strings contain only basic ASCII characters. They copy, paste, search and compare without surprises. Localized strings carry more risk. These are documented behaviors to be aware of:
- Invisible spacing characters: newer CLDR data uses a narrow no-break space (U+202F) between the time and AM/PM in US English. The text looks identical to an ordinary space, but code or tests that expect a regular space, or that split or parse the string, can fail.
- Directional marks: output for right-to-left locales such as Arabic or Hebrew can include invisible bidirectional control characters, for example U+200F or U+061C. These control the reading order of digits and separators. Removing them, or joining the string with text in another direction, can make the date display in the wrong visual order.
- Variation over time: an engine or locale-data update can change the punctuation or spacing of localized output. Stored or hard-coded localized strings can stop matching freshly formatted ones.
- Ambiguity once out of context: a shared string such as 01/02/2030 means different dates in different regions, and local-time output without a zone label loses the reference point.
For accessibility, localized wording such as a spelled-out month name is generally easier to follow than a compact numeric string. No screen reader or specific sharing destination was tested for this review, so there is no evidence here about how a particular assistive technology reads ISO strings or localized output that contains directional marks. Test with the tools your audience uses. On web pages, the HTML time element lets you show localized text while keeping an ISO value in its datetime attribute. Readers get natural wording, and software gets an unambiguous value.
When the plain ISO string is the better choice
Choose toISOString() or toJSON() whenever the string will be stored, sent to another system, used as a key, sorted, logged for later analysis or parsed again. Choose localized formatting only for the final layer people read. Generate it from the stored value when it is displayed, and set the locale and time zone explicitly. If a localized date is likely to be copied into another system, provide the ISO equivalent next to it. Newer date APIs, such as the Temporal proposal, are appearing in some environments. Check support in your target runtimes before relying on them in place of Date and Intl.