Course contentsShow
← JavaScript
Lesson 2208 of 2,72346. InternationalizationFree lesson

Creating Basic DateTimeFormat Instances

Learn to instantiate Intl.DateTimeFormat with locales and format dates according to regional conventions.

Creating Basic DateTimeFormat Instances

What you'll learn: How to create Intl.DateTimeFormat instances that automatically format dates according to regional conventions.

Why DateTimeFormat Matters

Just as currencies and numbers vary across regions, so do date and time formats. What Americans write as "12/25/2023" might appear as "25/12/2023" in the UK or "2023-12-25" in Sweden. The Intl.DateTimeFormat API handles these differences automatically.

Creating Your First Instance

You instantiate DateTimeFormat similarly to NumberFormat, passing a locale string:

const formatter = new Intl.DateTimeFormat('en-US');
const date = new Date('2023-12-25');
console.log(formatter.format(date)); // "12/25/2023"

Different Locales, Different Formats

The same date appears differently based on the locale:

const date = new Date('2023-12-25');

const usFormat = new Intl.DateTimeFormat('en-US');
console.log(usFormat.format(date)); // "12/25/2023"

const ukFormat = new Intl.DateTimeFormat('en-GB');
console.log(ukFormat.format(date)); // "25/12/2023"

const deFormat = new Intl.DateTimeFormat('de-DE');
console.log(deFormat.format(date)); // "25.12.2023"

Using the Browser's Default Locale

Omit the locale argument to use the user's system locale:

const formatter = new Intl.DateTimeFormat();
console.log(formatter.format(new Date())); // Formatted per user's locale

The Core Pattern

Think of DateTimeFormat as a translator that knows how every region writes dates. You create the translator once with a target language (locale), then reuse it to format multiple dates consistently.

Key Takeaway: new Intl.DateTimeFormat(locale) creates a reusable formatter that converts JavaScript Date objects into strings following regional conventions—simply call .format(date) to get properly localized output.