get client time zone from browser

confucius picture confucius · Aug 4, 2011 · Viewed 207.4k times · Source

Is there a reliable way to get a timezone from client browser? I saw the following links but I want a more robust solution.

Auto detect a time zone with JavaScript

Timezone detection in JavaScript

Answer

Wallace picture Wallace · May 29, 2016

Half a decade later we have a built-in way for it! For modern browsers I would use:

const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(tz);

This returns a IANA timezone string, but not the offset. Learn more at the MDN reference.

Compatibility table - as of March 2019, works for 90% of the browsers in use globally. Doesn't work on Internet Explorer.