浏览器控制台
console.log(Date.parse(new Date()),Date.now(),new Date().getTime(),+new Date());
输出:
1555925489000 1555925489767 1555925489767 1555925489767
为什么Date.parse(new Date()) 舍弃了最后三位,不应该是毫秒级吗?
官网解释:
method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC
据我猜测:调用Date.parse(new Date())时,JS引擎先会先调用new Date()的toString()方法,将其转换为字符串,而toString()转换的字符串只有精确到秒的表示,所以Date.parse之后,自然丢失了毫秒。