Detect timezone abbreviation using JavaScript

Stephen Sorensen picture Stephen Sorensen · Dec 23, 2009 · Viewed 60k times · Source

I need a way to detect the timezone of a given date object. I do NOT want the offset, nor do I want the full timezone name. I need to get the timezone abbreviation.

For example, GMT, UTC, PST, MST, CST, EST, etc...

Is this possible? The closest I've gotten is parsing the result of date.toString(), but even that won't give me an abbreviation. It gives me the timezone's long name.

Answer

Stephen DuMont picture Stephen DuMont · Dec 21, 2015

A native solution:

var zone = new Date().toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2]
console.log(zone)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

You can pass undefined instead of en-us to default to the browser's current locale.