↓ Ir para o conteúdo principal

← todas as notas

📎 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().timeZone returns the system IANA timezone name in newer browsers.
  • Some answers use Date.toString() or Date.toTimeString() to extract strings like GMT-0400, EST, or Pacific Daylight Time.
  • Library-based answers use moment-timezone, moment().utcOffset(), dayjs().utcOffset(), or jstz.determine().name() to guess or read the timezone.
  • Several snippets convert the offset into hour or hh:mm formats by dividing and padding the value from getTimezoneOffset().