I\'m trying to pull just the year out of a date, but for some reason on the first day of the year its returning the year previous.
new Date(\'2012-01-01\').g
new Date(dateString) will return what time it was in Greewich England at that time. You could do this if you want the year you seek:
new Date('2012-01-01T00:00:00').getFullYear();
Maybe you like this:
function dateFromString(dateString){
return new Date(dateString+'T00:00:00');
}
console.log(dateFromString('2012-01-01').getFullYear());