我完全不知道为什么以下代码在2019年1月3日当天执行此操作时会给我2021年...什么...我缺少什么...所以我需要一个我认为编码伙伴坐在我旁边。>。<< / p>
function daysTillChristmas()
{
var today = new Date();
var christmasDay1 = new Date(today.getFullYear() +1, 12, 25);
var test = today.getFullYear() + 1;
var christmasDay2 = new Date(2020, 12, 25);
console.log(today);
console.log("Today: " + today);
console.log("Today Full Year: " + today.getFullYear());
console.log("ChristmasDay1: " + christmasDay1);
console.log(christmasDay2);
console.log("ChristmasDay2: " + christmasDay2);
console.log("Test: " + test);
}
我的输出是...
"2019-01-03T22:54:33.294Z"
Today: Thu Jan 03 2019 14:54:33 GMT-0800 (Pacific Standard Time)
Today Full Year: 2019
ChristmasDay1: Mon Jan 25 2021 00:00:00 GMT-0800 (Pacific Standard Time)
"2021-01-25T08:00:00.000Z"
ChristmasDay2: Mon Jan 25 2021 00:00:00 GMT-0800 (Pacific Standard Time)
Test: 2020
顺便说一句...目前,我正在学习Javascript,并且正在使用以下URL来测试代码并获得一些练习。
浏览器:Chrome 70.0.3538.77 32位
https://www.w3resource.com/javascript-exercises/javascript-basic-exercises.php#EDITOR