thử nghiệm trong nút giao diện điều khiển:moment.js - UTC không làm việc như tôi mong đợi nó
var moment = require('moment');
// create a new Date-Object
var now = new Date(2013, 02, 28, 11, 11, 11);
// create the native timestamp
var native = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
// create the timestamp with moment
var withMoment = moment.utc(now).valueOf()
// it doesnt matter if i use moment(now).utc().valueOf() or moment().utc(now).valueOf()
// native: 1364469071000
// withMoment: 1364465471000
native === withMoment // false!?!?!
// this returns true!!!
withMoment === now.getTime()
tại sao isnt mẹ đẻ timestamp giống như withMoment? tại sao withMoment trả về dấu thời gian được tính từ thời gian cục bộ hiện tại? làm thế nào tôi có thể đạt được rằng moment.utc() trả về giống như Date.UTC()?
đã thử điều đó và thấy rằng nó hoạt động. đây có phải là lựa chọn duy nhất tôi có không? suy nghĩ moment.js giúp tôi tiết kiệm mã và thời gian ;-( – hereandnow78
Bạn có thể chuyển 'native' thành' moment.utc() 'thay vì' now', điều đó cũng sẽ hoạt động. – robertklep
yeah, vẫn không phải những gì tôi muốn, nhưng ty ;-) – hereandnow78