Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
日期函数在javascript中返回不正确的值_Javascript_Date - Fatal编程技术网

日期函数在javascript中返回不正确的值

日期函数在javascript中返回不正确的值,javascript,date,Javascript,Date,结果是:2017年3月3日星期五00:00:00 GMT+0100 没有参数是正确的: //var d = new Date(year, month, day, hours, minutes, seconds, milliseconds); new Date(2017,01,31); 结果是:2017年2月1日星期三23:10:22 GMT+0100 为什么?新日期2017年1月31日 月份是基于0索引的 因此,这里是2017年2月31日,因为2月没有31日,它将移动到3月,并将其余日期相加。

结果是:2017年3月3日星期五00:00:00 GMT+0100

没有参数是正确的:

//var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
new Date(2017,01,31);
结果是:2017年2月1日星期三23:10:22 GMT+0100

为什么?

新日期2017年1月31日

月份是基于0索引的

因此,这里是2017年2月31日,因为2月没有31日,它将移动到3月,并将其余日期相加。即2月28日+3天,即3月3日


希望对您有所帮助

oooooo www,本月从0开始。另请参见:
new Date()