相关代码
var time = new Date()
console.log(Date.now(time));
console.log(Date.parse(time));
console.log(time.getTime());
console.log((new Date(time)).getTime());
console.log(time.valueOf());
问题
Date.now
与 Date.parse
好似并不能准确的表达时间,这是为什么?
var time = new Date();
time.toString = function(){console.log('time.toString called'); return Date.prototype.toString.apply(this);}
console.log(Date.parse(time))
// 修一下,toString 加上 milliseconds
time.toString = function(){return `${this.getFullYear()}-${this.getMonth()+1}-${this.getDate()} ${this.getHours()}:${this.getMinutes()}:${this.getSeconds()}.${this.getMilliseconds()}`};
console.log(time.valueOf() === Date.parse(time))