首页 > 解决方案 > momentjs 如何使时区数据保持最新

问题描述

由于时区数据会发生变化,尤其是夏令时规则,momentjs 如何及时了解这些信息?

如果我将 momentjs-timezone 用于依赖于时区的调度系统,我是否需要进行任何维护以使时区数据保持最新?如果 momentjs 自动管理这个,它是如何做到的?

标签: javascriptnode.jstimezonemomentjsmoment-timezone

解决方案


From the moment-timezone docs:

The data for Moment Timezone comes from the IANA Time Zone Database. New versions are released periodically as time zone laws change in various countries.

The versions are named after the year and an incrementing letter. 2014a 2014b 2014c...

In order to keep versions together, Moment Timezone has a bundled object format as well.

You can access both the moment.tz version and data version:

const moment = require("moment-timezone");
console.log(`moment.version: ${moment.tz.version}`);
console.log(`moment.dataVersion: ${moment.tz.dataVersion}`);

This will look like:

moment.version: 0.5.33

moment.dataVersion: 2021a

You can see from the dataVersion how up to date the timezone data is and whether it needs updating.

You will need to update your installed version using npm / yarn to get any timezone changes.


推荐阅读