【问题标题】:How to get time zone using moment format如何使用矩格式获取时区
【发布时间】:2019-03-03 05:51:41
【问题描述】:

我需要使用 moment 获取当前时区 我已经给出了这样的代码

console.log(moment.utc(new Date()).format('Z'),moment.utc(new Date()),'moment')

得到类似的结果

我想获得 +0530,但现在我获得 +00:00,我们怎么才能获得呢!

【问题讨论】:

标签: time timezone momentjs gmt angular-moment


【解决方案1】:

您应该简单地使用moment() 而不是moment.utc()

默认情况下,moment 解析并显示为当地时间。

如果要解析或显示 UTC 时刻,可以使用 moment.utc() 而不是 moment()

这为我们带来了 Moment.js 的一个有趣特性。 UTC 模式。

在 UTC 模式下,所有显示方式都会以 UTC 时间显示,而不是本地时间。

另请参阅Local vs UTC vs Offset 指南。

【讨论】:

    猜你喜欢
    • 2019-11-18
    • 2022-01-11
    • 2021-01-23
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    相关资源
    最近更新 更多