Detect timezone abbreviation using JavaScript

后端 未结 16 2169
清酒与你
清酒与你 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 02:44

    import { tz } from 'moment-timezone';
    import * as moment from 'moment';
    
    const guess = tz.guess(true);    // "Asia/Calcutta"
    const zone = tz.zone(guess);     // return Zone object 
    zone.abbr(new Date().getTime())  // "IST" 
    // once u pass timestamp it'll return timezone abbrevation.
    

提交回复
热议问题