moment/moment-timezone 中是否有任何内置函数可以将时区名称转换为 "human readable format"?

Is there any built-in function in moment/moment-timezone to convert from a timezone name to a "human readable format"?

以我正在处理的项目的以下 minimal reproducible example 为例,我收到一个时区名称,我需要将其转换为 "human-readable format".

即:

我现在,您可能认为 "America/Los_Angeles" 已经是 "human-readable" 我同意,但我的问题要求将其转换为上述格式(或类似格式,不包括斜线、下划线等)。

此外,这可以使用正则表达式轻松实现,但是由于 moment and moment timezone 被用作项目的一部分......我想知道,有没有办法使用任何内置的 -在这些库提供的机制中?


import 'moment-timezone';
import * as moment from 'moment';

const tz = moment.tz.zone("America/Los_Angeles");

const result = tz.name;

console.log(result);  // America/Los_Angeles, need "America Los Angeles"

如果有任何帮助,这在 Angular 项目中。

这在 the docs on formatting 中得到解决:

Moment.js also provides a hook for the long form time zone name. Because these strings are generally localized, Moment Timezone does not provide any long names for zones.

To provide long form names, you can override moment.fn.zoneName and use the zz token.

var abbrs = {
    EST : 'Eastern Standard Time',
    EDT : 'Eastern Daylight Time',
    CST : 'Central Standard Time',
    CDT : 'Central Daylight Time',
    MST : 'Mountain Standard Time',
    MDT : 'Mountain Daylight Time',
    PST : 'Pacific Standard Time',
    PDT : 'Pacific Daylight Time',
};

moment.fn.zoneName = function () {
    var abbr = this.zoneAbbr();
    return abbrs[abbr] || abbr;
};

moment.tz([2012, 0], 'America/New_York').format('zz');    // Eastern Standard Time
moment.tz([2012, 5], 'America/New_York').format('zz');    // Eastern Daylight Time
moment.tz([2012, 0], 'America/Los_Angeles').format('zz'); // Pacific Standard Time
moment.tz([2012, 5], 'America/Los_Angeles').format('zz'); // Pacific Daylight Time