I’ve read about the function getYear in Javascript and how the result differs between browsers. Since I’ve been maintaining an application which uses the getYear method everywhere, I should probably refactor it to getFullYear.
But I don’t understand why the result from the getYear method differs in IE on specific dates, e.g. 28-march-2012.
//IE 28-march-2012
var now = new Date();
now.getYear();
//=2012
//IE 29-march-2012
//var now = new Date();
//now.getYear();
//=112
I ran this code in IE9, Windows 7, Timezone UTC +1 Amsterdam on 28 march 2012 and 29 march 2012 and just don’t understand where the difference is coming from. I hope it’s not to obvious…
You already answered your question:
getYear()is deprecated and you should usegetFullYear()instead.I tried your example and both dates result in 112 for me on IE9. More info about the algorith is available on MSDN.