简体   繁体   中英

Javascript Date.getFullYear() behaving same as Date.getYear()

I'm trying to get the year using Javascript. I instantiated a new Date(). I was able to get the month and date without issue. The year is not working as it should. I am using getFullYear() as all the docs and comments say to, not getYear() but, I get 117 instead of 2017. According to everything I've read getYear() should return 117 and getFullYear() should return 2017. In the console, if I run ' (new Date()).getFullYear() ' I get 2017.

If I declare the Task function in the console and then instantiate a new Task object, everything works properly. The task object's year property will be 2017.

What am I doing wrong?

 function Task(task) { var d = new Date(); this.task = task; this.date = d.getDate(); this.month = d.getMonth(); this.year = d.getFullYear() this.complete = false; } var task = new Task("task one"); ['date', 'month', 'year'].forEach(function(p) { console.log(p + ' is ' + task[p]); }); // date is 28 // month is 8 // year is 117

I was using the incorrect js file. The file I had updated with getFullYear() is not the one that was being run. The one that was being run was using getYear().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM