在node.js中使用moment-timezone

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

当尝试使用特定时区的日期时,出现以下错误:

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.

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

node.js momentjs moment-timezone
1个回答
0
投票

您犯了一个小错误。

给出

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();

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