Course contentsShow
← JavaScript
Lesson 1648 of 2,72335. Standard Library and Built-insFree lesson

Intl.DateTimeFormat: Basic Date Formatting

Format dates with locale-specific conventions for day, month, year order and separators.

Intl.DateTimeFormat: Basic Date Formatting

You'll learn how to format dates according to different locales' conventions without hardcoding date formats.

The Problem with Manual Date Formatting

Different regions display dates completely differently. Americans write "12/25/2023" (month/day/year), Europeans write "25/12/2023" (day/month/year), and ISO standard uses "2023-12-25" (year/month/day). Instead of building custom formatters for each region, Intl.DateTimeFormat does this automatically.

How DateTimeFormat Works

Intl.DateTimeFormat takes a locale code (like 'en-US' or 'de-DE') and returns a formatter object with a .format() method:

const date = new Date(2023, 11, 25); // December 25, 2023

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

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

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

Notice how the day/month order and separators change automatically based on locale conventions.

Think of It Like a Translator

Just as a language translator adapts phrases to local customs, DateTimeFormat adapts dates to regional expectations. A German user sees dots as separators because that's their standard; an American sees slashes.

// Same date, formatted for user's browser locale
const userFormatter = new Intl.DateTimeFormat();
console.log(userFormatter.format(new Date())); // Adapts to browser's language setting

Key Takeaway: Intl.DateTimeFormat automatically formats dates according to locale-specific conventions for day/month/year order and separators, eliminating the need to manually handle regional differences.