Apparently, the javascript getYear () date object method returns a different result between IE8 and Firefox3.6 (I have these 2 on my machine, not sure about another browser or version)
Date d = new Date(); alert(d.getYear()); FF3.6 ==> 111 (year since 1900? i guess) IE8 ===> 2011
I tested only Firefox, and now my Javascript code, which adjusts the return value of getYear (), now gives me 3911 due to my encoding.
var modified = d.getYear() + 1900
In Firefox, this will return 2011. But if I applied this approach to IE8, it will return 3911.
I could add logic to distinguish between IE and Firefox, but I don't want to add such if / else everywhere in my code wherever there are browser-dependent parts like this. Is there any other way to approach this problem?
var browserName=navigator.appName; if (browserName=="Netscape") { var modified = d.getYear() + 1900 } else if(browserName=="Microsoft Internet Explorer") { var modified = d.getYear(); }
javascript date browser-detection
masato-san
source share