Skip to content

Instantly share code, notes, and snippets.

@MikSDigital
Last active January 9, 2020 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikSDigital/7d789574b53214f511b57273ab9e9a9e to your computer and use it in GitHub Desktop.
Save MikSDigital/7d789574b53214f511b57273ab9e9a9e to your computer and use it in GitHub Desktop.
get timezone string
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