To get the current timezone in JavaScript, call the Intl.DateTimeFormat()
method. This method returns an object whose one of the properties is resolvedOptions
. resolvedOptions is a method when called, returns an object.
Intl.DateTimeFormat().resolvedOptions()
Output
{ locale: "en-GB", calendar: "gregory", numberingSystem: "latn", timeZone: "Asia/Kolkata", year: "numeric", month: "2-digit", day: "2-digit" }
After that, you need to access the timeZone property to get the timezone.
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone); //"Asia/Calcutta"
There are other ways to get the timezone, but they are ineffective because they give you the timezone offset in minutes and not in UTC or GMT format.
let date = new Date(); console.log(date); console.log(date.getTimeZoneOffset());
Output
Wed May 04 2022 09:12:00 GMT+0530 (India Standard Time) -330