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

Time Zones with the timeZone Option

Format dates in any IANA time zone by passing the timeZone option to DateTimeFormat instances.

Time Zones with the timeZone Option

What you'll learn: How to format dates in any specific time zone using the timeZone option in Intl.DateTimeFormat.

Why Time Zones Matter

By default, DateTimeFormat uses the user's local time zone. But what if you need to display a date in Tokyo time, regardless of where your user is located? Or show meeting times in multiple time zones simultaneously? That's where the timeZone option comes in—it lets you override the default and format dates for any location.

Specifying a Time Zone

The timeZone option accepts IANA time zone identifiers like "America/New_York", "Europe/London", or "Asia/Tokyo". Think of these as precise geographic locations that account for daylight saving time and historical time zone changes.

const date = new Date('2024-01-15T12:00:00Z'); // Noon UTC

const tokyo = new Intl.DateTimeFormat('en-US', {
  timeZone: 'Asia/Tokyo',
  dateStyle: 'short',
  timeStyle: 'short'
});

console.log(tokyo.format(date)); // "1/15/24, 9:00 PM"

The same UTC moment appears differently in New York:

const newYork = new Intl.DateTimeFormat('en-US', {
  timeZone: 'America/New_York',
  dateStyle: 'short',
  timeStyle: 'short'
});

console.log(newYork.format(date)); // "1/15/24, 7:00 AM"

The Power of Consistency

The timeZone option ensures your dates render in the target time zone, not the viewer's local zone. This is crucial for international applications, scheduling systems, or any scenario where the location of an event matters more than the user's current location.

Key Takeaway: Use the timeZone option with any valid IANA time zone identifier to format dates consistently for specific geographic locations, independent of the user's local settings.