Date and Time Styles
You'll learn how to format dates quickly using convenient style presets instead of manually configuring every piece.
When formatting dates and times, you could individually specify every component (year format, month format, day format, etc.)—but that's tedious. The Intl.DateTimeFormat API offers a shortcut: dateStyle and timeStyle options that apply pre-configured patterns for common formatting needs.
What Are Date and Time Styles?
These options accept four values: "full", "long", "medium", or "short". Each applies a locale-appropriate format with varying levels of detail:
full: Maximum detail (day of week, full month name, year, timezone)long: Detailed but slightly shortermedium: Balanced readabilityshort: Compact, numeric-focused
Think of these like clothing sizes: "full" is a three-piece suit, "short" is casual wear—both appropriate, just different contexts.
Using Date and Time Styles
const date = new Date('2024-03-15T14:30:00');
// Date styles only
const fullDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'full' });
console.log(fullDate.format(date)); // "Friday, March 15, 2024"
const shortDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'short' });
console.log(shortDate.format(date)); // "3/15/24"
// Time styles only
const longTime = new Intl.DateTimeFormat('en-US', { timeStyle: 'long' });
console.log(longTime.format(date)); // "2:30:00 PM GMT-5"
// Combine both
const mediumBoth = new Intl.DateTimeFormat('en-US', {
dateStyle: 'medium',
timeStyle: 'short'
});
console.log(mediumBoth.format(date)); // "Mar 15, 2024, 2:30 PM"
Important Constraint
You cannot mix dateStyle/timeStyle with granular component options like year, month, or hour. It's one approach or the other—presets or full customization.
Key Takeaway: Use dateStyle and timeStyle with full, long, medium, or short for quick, locale-aware date/time formatting without manually configuring every component.