在Node.js中使用时刻时区



尝试使用特定时区的日期时,我收到以下错误:

const dayInGermany = moment().tz("2020-01-31 13:00", "Europe/Berlin").toISOString();

Moment Timezone has no data for 2020-01-31 13:00. See http://momentjs.com/timezone/docs/#/data-loading/.

页面 https://momentjs.com/timezone/docs/#/data-loading/说:

In Node.js, all the data is preloaded. No additional code is needed for loading data.

如何将时区数据添加到我的项目中?

你犯了一个小错误。

鉴于

const moment = require('moment-timezone');

它应该是

const dayInGermany = moment.tz("2020-01-31 13:00", "Europe/Berlin").toISOString();

const dayInGermany = moment().tz("2020-01-31 13:00", "Europe/Berlin").toISOString();

最新更新