spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.98k stars 184 forks source link

Short Timezone Name in Formatter #348

Open timsayshey opened 2 years ago

timsayshey commented 2 years ago

The {timezone} format only returns location names like America/Chicago. Can we get a {timezone-short} that returns the timezone acronym, ie CST? Or is it already available?

spencermountain commented 2 years ago

hey Tim, sorry for the delay. Yeah, this is a good idea. I've got acronym display working over here, but it would require a bit of business to do what you've described - the acronym sometims changes during dst.

These acronyms are really fraught, but also very widely used. Going from acronym->iana is a mess, but going from iana-> acronym should be possible.

yeah, i like this - i may try doing it as a plugin. if you wanted to work on it together, let me know. cheers

timsayshey commented 2 years ago

Hi Spencer - That's great to hear!

Here's the vanilla JS workaround that I'm using right now. Actually works really well and seems very accurate: new Date().toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2]