转载地址:https://w3ctrain.com/tags/new-Date/
JavaScript中可以在某个元素前使用 ‘+’ 号,这个操作是将该元素转换秤Number类型,如果转换失败,那么将得到 NaN。
所以 +new Date 将会调用 Date.prototype 上的 valueOf 方法,而根据 MDN ,Date.prototype.value 方法等同于 Date.prototype.getTime() 。
所以下列代码效果相同:
console.log(+new Date);
console.log(new Date().getTime());
console.log(new Date().valueOf());
console.log(new Date() * 1);