Last active
January 9, 2020 08:36
-
-
Save MikSDigital/7d789574b53214f511b57273ab9e9a9e to your computer and use it in GitHub Desktop.
get timezone string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTimeZoneString() { | |
var abbr = ""; | |
try { | |
abbr = new Intl.DateTimeFormat().resolvedOptions().timeZone; | |
} catch (e) { | |
abbr = "" | |
} | |
return abbr || ""; | |
} | |
// with options | |
function getTimeZoneStr() { | |
var abbr = ""; | |
try { | |
abbr = new Intl.DateTimeFormat('en-US', { | |
hour: 'numeric', | |
hour12: false, | |
timeZoneName: "long" | |
}).resolvedOptions().timeZone; | |
} catch (e) { | |
abbr = "" | |
} | |
return abbr || ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment