Advertisement
Advanced JavaScript, Date, Time & Internationalization (Intl API)

Why is manually working with time zones using the Date object error-prone?

Short answer

The built-in Date object always represents a single instant in time and only exposes it in either UTC or the *local system's* time zone — there's no built-in way to reliably format a date in an arbitrary, different time zone without extra options or a library.

Save JavaScript mock interview
Advertisement
AModel answer
The built-in Date object always represents a single instant in time and only exposes it in either UTC or the *local system's* time zone — there's no built-in way to reliably format a date in an arbitrary, different time zone without extra options or a library.
// Formatting in a specific, non-local zone requires Intl:
new Intl.DateTimeFormat('en-US', {
  timeZone: 'America/New_York', timeStyle: 'short'
}).format(new Date());
Real-world example
Showing a meeting time correctly in both the organizer's and an attendee's time zones.
Likely follow-ups
  • What does the newer Temporal API aim to fix about Date's time zone handling?
Related topics