Date & Time Formatting
Displaying dates and times according to locale-specific conventions.
Definition
Date and time formatting varies significantly across locales. The same date might be displayed as MM/DD/YYYY (US), DD/MM/YYYY (Europe), or YYYY-MM-DD (ISO/Asia). Times vary in 12/24-hour format, separators, and timezone display. The JavaScript Intl.DateTimeFormat API and libraries like date-fns or Luxon handle locale-aware formatting.
Examples
- →US: 02/03/2024 (MM/DD/YYYY)
- →UK: 03/02/2024 (DD/MM/YYYY)
- →ISO: 2024-02-03 (YYYY-MM-DD)
- →Time: 3:00 PM (US) vs 15:00 (Europe)
Frequently Asked Questions
Should I use native Intl API or a library?
Intl.DateTimeFormat is built-in, well-supported, and sufficient for most cases. Libraries (date-fns, Luxon, Day.js) add: easier manipulation, relative time ('2 hours ago'), better timezone handling. Use Intl for display, library for complex operations.
How do I handle timezones in a global app?
Store in UTC always. Display in user's timezone using Intl.DateTimeFormat with timeZone option. Let users set preferred timezone in settings. Show timezone indicator for scheduled events. Libraries like Luxon simplify timezone math.