Detect timezone abbreviation using JavaScript

后端 未结 16 2131
清酒与你
清酒与你 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:45

    The Date object doesn't have a method for getting the timezone abbreviation, but it is implicit at the end of the result of toString. For example,

    var rightNow = new Date();
    alert(rightNow);
    

    ...will return something like Wed Mar 30 2011 17:29:16 GMT-0300 (ART). The timezone abbreviation can be isolated between parentheses:

    var rightNow = new Date();
    alert(String(String(rightNow).split("(")[1]).split(")")[0]);
    

    The output will be the timezone abbreviation, like ART.

提交回复
热议问题