【发布时间】:2019-04-09 03:38:37
【问题描述】:
我使用 Moment js 得到同一日期不同毫秒的错误。
我正在从服务器 ('-2208988800000') 获取数据。我转换了'DD-MMM-YYYY' 中的值。现在我又想要相同的毫秒,为什么我得到相同日期的不同毫秒?这是我的代码
http://plnkr.co/edit/1QoWLoFqkNAe2ebZ0V01?p=preview
我有两个控制台x1 和x2。它们是不同的,为什么?
var x = '-2208988800000'
var d = new Date(moment(new Date(parseInt(x)).toUTCString()).format('DD-MMM-YYYY'));
console.log(d)
var x2 = moment(new Date(d).toUTCString()).format('x');
console.log(x2)
// why x1 and x2 is different
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
我怎样才能得到相同的值?
【问题讨论】:
标签: javascript angularjs momentjs angular-moment