Detect timezone abbreviation using JavaScript

后端 未结 16 2170
清酒与你
清酒与你 2020-11-30 02:17

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.

16条回答
  •  甜味超标
    2020-11-30 02:48

    Not possible with vanilla JavaScript. Browsers are inconsistent about returning timezone strings. Some return offsets like +0700 while others return PST.

    It's not consistent or reliable, which is why you need 3rd party script like moment.js (and moment-timezone.js) or create your own hashtable to convert between offsets and timezone abbreviations.

提交回复
热议问题