且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用moment.js库获取时区列表?

更新时间:2022-12-14 09:39:20

对于时区,您应该手动添加自己制作的时区JS文件.

For timezone, you should manually add timezone JS file made by yourself.

在此页面中,您可以选择区域并生成一个文件,然后将其加载首先加载moment.js.

In this page, you can pick the zones up and generate a file to be loaded after you load moment.js first off.

您应该有类似的东西,看看:

You should have something like this, take a look:

<script src="/javascripts/modules/moment/moment-with-langs.min.js"></script>
<script src="/javascripts/modules/moment/moment-timezone.min.js"></script>
<script src="/javascripts/modules/moment/moment-timezone-data.js"></script>

JS moment-timezone-data.js是时区的自定义列表.

The JS moment-timezone-data.js is the custom list of the timezones.

但是,到目前为止,我知道,MomentJS 不会为您返回所有时区的列表,因为时区也可以更改.如果您需要填充select标记,建议您从上面的链接中手动解析时区列表.

However, so far I know, MomentJS does not return for you a list of all timezones, because timezone can be changed as well. If you need to populate a select tag, I suggest you parse the timezone list manually from the link above.