使用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>
如何获得相同的值?