Time Zone Display in Formatted Dates
What you'll learn: How to explicitly show timezone names and offsets in your formatted date strings using Intl.DateTimeFormat options.
The Core Idea
When displaying dates to users, you often need to clarify which timezone the date represents. The Intl.DateTimeFormat API provides the timeZoneName option to control how timezone information appears in your formatted output, working hand-in-hand with the timeZone option you've already learned.
Think of it like showing a temperature: saying "72 degrees" is ambiguous, but "72°F" or "72°C" makes it crystal clear. Similarly, "3:00 PM" is vague, but "3:00 PM EST" or "3:00 PM UTC-5" removes all doubt.
The timeZoneName Option
The timeZoneName option accepts several values that control the display format:
"short"– Abbreviated timezone (e.g., "PST", "GMT+1")"long"– Full timezone name (e.g., "Pacific Standard Time")"shortOffset"– Short offset format (e.g., "GMT-8")"longOffset"– Long offset format (e.g., "GMT-08:00")"shortGeneric"– Generic short name (e.g., "PT")"longGeneric"– Generic long name (e.g., "Pacific Time")
const date = new Date('2024-01-15T15:30:00Z');
const shortFormatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
timeStyle: 'short',
timeZoneName: 'short'
});
console.log(shortFormatter.format(date));
// "10:30 AM EST"
const longFormatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
timeStyle: 'short',
timeZoneName: 'long'
});
console.log(longFormatter.format(date));
// "10:30 AM Eastern Standard Time"
Key Takeaway: Use the timeZoneName option alongside timeZone to display timezone information clearly in formatted dates, choosing between abbreviated names, full names, or offset formats depending on your UI needs.