Display users local zone abbreviation

后端 未结 5 1942
耶瑟儿~
耶瑟儿~ 2020-12-17 10:17

I was trying to use z or zz in format to display the timezone at the end of the string and found that it\'s deprecated. Z and ZZ

5条回答
  •  清歌不尽
    2020-12-17 10:52

    2020 Update

    Some time in the past 5 years, this stopped working. Now try:

    var timeZone = moment.tz.guess();
    var time = new Date();
    var timeZoneOffset = time.getTimezoneOffset();
    moment.tz.zone(timeZone).abbr(timeZoneOffset);
    

提交回复
热议问题