Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Intl.DateTimeFormat — localized date and time formatting

Intl.DateTimeFormat formats dates and times using locale conventions and a selected time zone. Learn format(), formatToParts(), resolvedOptions(), and the distinction between timeZone and hourCycle.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const formatter = new Intl.DateTimeFormat(locales, options);
formatter.format(date);
formatter.formatToParts(date);
formatter.resolvedOptions();

Intl.DateTimeFormat belongs to the ECMA-402 internationalization standard, not the DOM API. Create a formatter with new Intl.DateTimeFormat(locales, options) and reuse it. A locale selects presentation conventions; it does not automatically select a time zone corresponding to that country.

The names Intl.DateTimeFormat.format and Intl.DateTimeFormat.formatToParts here mean instance operations, not static constructor methods. formatter.format(date) returns text; the format property is an accessor exposing a bound function. formatter.formatToParts(date) returns ordered { type, value } objects, including literal parts. Joining every value reconstructs format(date). Do not parse localized text by splitting on separators.

timeZone, such as UTC or Europe/Warsaw, selects the zone used to display the same instant without changing the Date object. Omitting it selects the environment's time zone. hourCycle selects the hour range: h11 is 0–11, h12 is 1–12, h23 is 0–23, and h24 is 1–24. It matters when formatting hours; the hour12 option takes precedence when supplied.

Intl.DateTimeFormat.prototype.resolvedOptions, called as formatter.resolvedOptions(), exposes the settings actually selected, including locale, timeZone, and, when the format includes hours, hourCycle. Locale data can differ between environments, so do not assume identical punctuation or spacing. The standard is not a browser compatibility table: check the required methods and options in your target environments; Node 24 does not establish browser support.

Examples

const formatter = new Intl.DateTimeFormat('en-GB', {
  timeZone: 'UTC',
  numberingSystem: 'latn',
  hour: '2-digit',
  minute: '2-digit',
  hourCycle: 'h23'
});
const date = new Date('2024-01-02T00:05:00Z');
const parts = formatter.formatToParts(date);
const field = type => parts.find(part => part.type === type).value;
console.log(`${field('hour')}:${field('minute')}`);
console.log(parts.map(part => part.value).join('') === formatter.format(date));
console.log(formatter.resolvedOptions().hourCycle);

Result

00:05
true
h23

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources