我最近在使用 momentjs,但刚刚切换到 dayjs。但是,我需要获取时区列表。使用 momentjs 非常简单:
moment.tz().names()
,但是使用 dayjs 我不知道该怎么做。我不想获得 500 多个时区,而是需要更短、更紧凑的列表,考虑到冬季/夏季时间的变化。
有什么想法吗?
在浏览器控制台中使用以下代码
for (const timeZone of Intl.supportedValuesOf('timeZone')) {console.log(timeZone)}
您可以使用
Intl.supportedValuesOf('timeZone')
。这将返回可用时区的名称。这不依赖于 dayjs。可以用
let timezones = Intl.supportedValuesOf("timeZone");
console.log(timezones)