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