如何使用dayJs获取时区名称列表

问题描述 投票:0回答:2

我最近在使用 momentjs,但刚刚切换到 dayjs。但是,我需要获取时区列表。使用 momentjs 非常简单:

moment.tz().names()
,但是使用 dayjs 我不知道该怎么做。我不想获得 500 多个时区,而是需要更短、更紧凑的列表,考虑到冬季/夏季时间的变化。

有什么想法吗?

javascript html jquery momentjs dayjs
2个回答
1
投票

在浏览器控制台中使用以下代码

 for (const timeZone of Intl.supportedValuesOf('timeZone')) {console.log(timeZone)}

0
投票

您可以使用

Intl.supportedValuesOf('timeZone')
。这将返回可用时区的名称。这不依赖于 dayjs。可以用

let timezones = Intl.supportedValuesOf("timeZone");
console.log(timezones)

© www.soinside.com 2019 - 2024. All rights reserved.