New Date(0) VS New Date(‘0’) VS New Date()

Date()对象作为js原生的时间库,不带参数时,总是返回表明当前时间的字符串

Date() // Wed Mar 24 2021 15:04:05 GMT+0800 (中国标准时间)

当Date()作为构造函数使用时,会返回一个Date对象的实例

const today=new Date();

js中,date语法有四种方式:

newDate();
newDate(value);
newDate(dateString);
newDate(year,monthIndex[,day[,hours[,minutes[,seconds[,milliseconds]]]]])

New Date(0)对应newDate(value),返回自1970年1月1日00:00:00UTC(theUnixepoch)以来的毫秒数,忽略了闰秒。
New Date( 0 )对应newDate(dateString),表明日期的字符串值。该字符串应该能被Date.parse()正确方法识别(即符合IETF-compliantRFC2822timestamps或versionofISO8601)。而Date.parse( 0 )的值为946656000000,刚好是2000年。

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...