📎 Webclip
Getting the client's timezone offset in JavaScript
The thread collects ways to read timezone data from the browser. The simplest answers use Date().getTimezoneOffset() for the offset in minutes, while later answers prefer Intl.DateTimeFormat().resolvedOptions().timeZone for an IANA timezone name. Other replies format Date.toString() or toTimeString() to extract an offset, abbreviation, or display label.
Reading notes#
Date.getTimezoneOffset()returns the difference between UTC and local time in minutes, with the sign reversed from the usual GMT notation.- The offset is not a full timezone identifier, and daylight saving time can change it during the year.
Intl.DateTimeFormat().resolvedOptions().timeZonereturns the system IANA timezone name in newer browsers.- Some answers use
Date.toString()orDate.toTimeString()to extract strings likeGMT-0400,EST, orPacific Daylight Time. - Library-based answers use
moment-timezone,moment().utcOffset(),dayjs().utcOffset(), orjstz.determine().name()to guess or read the timezone. - Several snippets convert the offset into hour or
hh:mmformats by dividing and padding the value fromgetTimezoneOffset().
