【问题标题】:momentjs does not change the date / time in accordance with the specified timezonemomentjs 不会按照指定的时区更改日期/时间
【发布时间】:2020-04-30 03:16:10
【问题描述】:

我正在使用 moment 和 moment-timezone 来输出存在日期(对于任何时区)。对于我的时区(亚洲/雅加达),今天 2020-04-22 17:30:00 是正确的。但是,它总是为任何时区输出 2020-04-22 17:30:00,这是不正确的。在下面的示例中,它应该显示 2020-04-22 15:30:00

const presence_end = "2020-04-22T17:30:00+07:00";
const end = Moment(presence_end).tz('Asia/Jayapura').format();
console.log(end) //the output is 2020-04-22 17:30:00```

【问题讨论】:

    标签: javascript node.js momentjs


    【解决方案1】:

    我无法完全复制您的结果,但我希望这会有所帮助。

    从下面的代码来看,时间似乎是正确的,从亚洲/雅加达时间 (+07:00) 到亚洲/查亚普拉时间 (+9:00)。

    如果雅加达是 17:30,那么查亚普拉应该是 19:30。

    const presence_end = "2020-04-22T17:30:00+07:00";
    const endJakarta = moment(presence_end).tz('Asia/Jakarta').format();
    console.log("Presence_end (Asia/Jakarta):", endJakarta )
    console.log("Presence_end (UTC):", moment(presence_end).toISOString());
    const endJayapura = moment(presence_end).tz('Asia/Jayapura').format();
    console.log("Presence_end (Asia/Jayapura):", endJayapura);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script> 
    <script src="https://momentjs.com/downloads/moment-timezone-with-data.js"></script> 

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 2013-09-21
      • 2016-03-12
      • 2016-01-30
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      相关资源
      最近更新 更多