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

Weekday and Era Options

Include weekday names and era indicators in formatted output using narrow, short, or long formats.

Weekday and Era Options

You'll learn how to include weekday names and era indicators (like "AD" or "BC") in your date formatting using Intl.DateTimeFormat.

The Core Idea

When formatting dates, you often want more context than just numbers. The weekday option lets you display which day of the week a date falls on, while the era option shows historical periods (useful for dates that might be BCE/CE). Both options support three verbosity levels: "narrow", "short", and "long".

Using the Weekday Option

The weekday option adds the day name to your formatted output:

const date = new Date('2024-03-15');

const narrow = new Intl.DateTimeFormat('en-US', { 
  weekday: 'narrow' 
}).format(date);
// "F" (Friday)

const short = new Intl.DateTimeFormat('en-US', { 
  weekday: 'short' 
}).format(date);
// "Fri"

const long = new Intl.DateTimeFormat('en-US', { 
  weekday: 'long' 
}).format(date);
// "Friday"

Using the Era Option

The era option displays the calendar era, particularly visible with historical dates:

const ancientDate = new Date('-000500-01-01'); // 500 BCE

const shortEra = new Intl.DateTimeFormat('en-US', {
  year: 'numeric',
  era: 'short'
}).format(ancientDate);
// "501 BC"

const longEra = new Intl.DateTimeFormat('en-US', {
  year: 'numeric',
  era: 'long'
}).format(ancientDate);
// "501 Before Christ"

Think of these options like choosing between a text message abbreviation ("Fri") versus writing the full word ("Friday")—same information, different context and formality.

Key Takeaway: Use weekday with "narrow", "short", or "long" to add day names, and era with the same values to show historical periods in your formatted dates, giving users richer temporal context.