Format localized dates and times with JavaScript Intl
How Intl.DateTimeFormat turns dates into localized text, how to get a yyyy-MM-dd HH:mm:ss string, and when its output works for copying and sharing.
JavaScript's Intl.DateTimeFormat converts a moment in time into text that follows a locale's conventions for order, separators, month names, numerals and 12- or 24-hour clocks. This review covers what that conversion changes, where it fits, and where a fixed, plain format such as yyyy-MM-dd HH:mm:ss serves better. It draws on documented behavior of the Intl API and general principles. No environment-specific tests were supplied, so claims about particular browsers, apps or screen readers are noted as open questions rather than findings.
Is Intl date formatting right for your use?
Use Intl when people will read the date. A reader in the US, the UK, Germany or Japan sees the date in a familiar form, and you don't have to maintain format tables yourself. The tradeoff is that the output is not stable. The same code can produce different strings in different locales, and sometimes in different runtime versions, because the formatting rules come from the engine's bundled locale data. That makes the output a poor fit for anything a program must parse, compare, sort, store or match exactly.
Use a plain, fixed format such as ISO 8601 or yyyy-MM-dd HH:mm:ss for:
- Log files, CSV exports and database fields
- Filenames, URLs and cache keys
- API payloads and any value another system will parse
- Text users are likely to paste into spreadsheets or search tools
- Automated tests that compare exact strings
What the transformation actually changes
A Date object stores a single instant as a count of milliseconds since the Unix epoch, measured in UTC. Intl.DateTimeFormat leaves that value unchanged. It produces a new string by applying three things: a locale's rules, a time zone (the runtime's default unless you set the timeZone option), and the fields and styles you request. The result is new stored characters, not a visual effect. Unlike CSS styling or bidirectional display, what you see is exactly what gets copied, saved or sent.
Several parts of the string can vary by locale:
- Field order: month-day-year, day-month-year or year-month-day
- Separators: slashes, dots, hyphens, or locale-specific characters such as the Japanese year, month and day markers
- Names: month and weekday names in the locale's language
- Numerals: some locales default to non-Latin digits unless you set the numberingSystem option
- Clock: 12-hour with a day-period marker, or 24-hour, controlled by hour12 or hourCycle
- Invisible characters: spacing and directional marks, covered in the next section
Typical short-date output for 5 January 2024 is shown below. The exact strings depend on the locale data in your engine, so check them in your own target runtimes.
const d = new Date(2024, 0, 5, 13, 45, 30);
new Intl.DateTimeFormat('en-US').format(d); // "1/5/2024"
new Intl.DateTimeFormat('en-GB').format(d); // "05/01/2024"
new Intl.DateTimeFormat('de-DE').format(d); // "5.1.2024"
new Intl.DateTimeFormat('ja-JP').format(d); // "2024/1/5"
The en-US and en-GB results show the main risk of numeric dates: the same digits mean different days to different readers. When the audience is mixed or unknown, spell out the month (month: 'long' or 'short') or use the dateStyle option.
Getting yyyy-MM-dd HH:mm:ss from Intl
Intl.DateTimeFormat does not accept pattern strings like yyyy-MM-dd HH:mm:ss. You choose fields and styles, and the locale decides how to arrange them. To build a fixed pattern while still getting Intl's time zone handling, use formatToParts and assemble the pieces yourself:
function formatYmdHms(date, timeZone) {
const parts = new Intl.DateTimeFormat('en-US', {
timeZone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hourCycle: 'h23',
numberingSystem: 'latn',
}).formatToParts(date);
const get = (type) => parts.find((p) => p.type === type).value;
return `${get('year')}-${get('month')}-${get('day')} ${get('hour')}:${get('minute')}:${get('second')}`;
}
formatYmdHms(new Date(), 'America/New_York');
Some details in this code are deliberate:
- hourCycle: 'h23' is used instead of hour12: false. Some engines have rendered midnight as hour 24 when only hour12: false was set.
- The locale is used only to get Latin digits and predictable parts. The separators come from the template string, not the locale.
- The timeZone option sets whose wall clock the output shows. If you leave it out, you get the runtime's default zone, which can differ between a server and a user's device.
- year: 'numeric' is not zero-padded, so years before 1000 come out with fewer than four digits. This matters only for historical data.
Two shortcuts are common but have limits. Formatting with a locale whose output happens to look like yyyy-MM-dd HH:mm:ss, often the Swedish locale, relies on locale data that no specification guarantees. Taking date.toISOString() and replacing the T always gives UTC, never local time. Both are acceptable only when you understand and accept those limits.
Will the result stay readable and usable after copying or sharing?
Localized strings can contain characters you cannot see. Recent locale data for several English locales puts a narrow no-break space (U+202F) between the time and AM or PM, where a regular space used to be. Right-to-left locales such as Arabic and Hebrew can include directional marks that control how the date displays among surrounding text. These characters survive copy and paste. They can break string comparisons, regular expressions that expect an ordinary space, naive parsers, and searches for the visible text. If you test with hard-coded expected strings, tests can fail after a runtime update even though nothing looks different.
Reading order is a related concern. Directional marks exist so a date displays correctly inside right-to-left text. Once you strip them, or paste the string into a field that handles bidirectional text differently, the parts can appear reordered. How a specific editor, messaging app or spreadsheet handles this was not tested for this review. Check each destination that matters to you.
For accessibility, a spelled-out format such as "January 5, 2024" leaves less room for ambiguity than numeric forms, whether a sighted reader or a screen reader is reading it. On web pages, a common practice is to wrap the localized text in an HTML time element whose datetime attribute holds the ISO value. People see the friendly version, and software has an unambiguous one. How individual screen readers announce particular localized formats or invisible characters was not tested here and may vary by product and settings.
When to keep a plain-text equivalent
| Use case | Recommended output |
| On-screen display for a known locale | Intl with dateStyle and timeStyle, or explicit fields |
| Mixed or unknown audience | Intl with a spelled-out month and the time zone shown |
| Storage, logs, APIs | ISO 8601, not Intl output |
| Exports users will paste or sort | Fixed yyyy-MM-dd HH:mm:ss built with formatToParts |
| Web pages needing both | Intl text plus an ISO datetime attribute |
In short, treat Intl output as presentation-only text. Keep the original Date or an ISO string as the source of truth, and generate localized text from it at the point of display.
Evidence gaps
This review relies on documented API behavior and general principles. No tests in particular browsers, Node.js versions, destination apps or assistive technologies were supplied. Exact output strings, especially their invisible characters, can change as locale data is updated. Verify them in the runtimes and destinations you actually support.