【问题标题】:how to convert date in UTC format using moment?如何使用时刻转换 UTC 格式的日期?
【发布时间】:2018-11-06 10:15:35
【问题描述】:

使用日期选择器我得到这个值 “Fri Jan 12 1900 05:21:10 GMT+0521 (India Standard Time)” 我想以 UTC 或 UTC 为单位获得它的值,以毫秒或长期价值。 这是我的代码

 app.controller('MainCtrl', function($scope, moment) {
 $scope.UTC ='';
      $scope.IST = 'Fri Jan 12 1900 05:21:10 GMT+0521 (India Standard Time)';
    });

【问题讨论】:

  • 您能检查我的答案并提供反馈吗?谢谢。

标签: javascript angularjs momentjs


【解决方案1】:

根据瞬间docs

moment.utc(yourDate).format()

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

如果要解析或显示 UTC 时间,可以使用 moment.utc() 代替 moment()。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    相关资源
    最近更新 更多