【问题标题】:Using moment-timezone in node.js在 node.js 中使用时刻时区
【发布时间】:2020-09-06 22:55:38
【问题描述】:

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

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】:

    你犯了一个小错误。

    给定

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

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 2018-01-17
      • 1970-01-01
      • 2018-10-27
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多