GetYear Function in Java Script is not working properly in firefox

Hi Folks,

I have found that some times in firefox getyear function is not working properly. For example.We define a date value with following.

var dtTo = new Date("11-Feb-2007");

Now if you do alert like

Alert(dtTo.getYear());

But in firefox year is displaying like 107.So to fix this issue. I have used getFullYear function like

Alert(dtTo.getFullYear());

And It's working fine...

Published Monday, February 11, 2008 10:30 AM by Jalpesh P. Vadgama

Comments

# re: GetYear Function in Java Script is not working properly in firefox

Monday, February 11, 2008 5:47 AM by Joost Aarts

Why use only 2 digits to denote a year? Havent we learned from y2k ?

# re: GetYear Function in Java Script is not working properly in firefox

Tuesday, February 12, 2008 12:04 AM by Jalpesh P. Vadgama

Some clients have specific requirement about displaying a year in two digits. And for your information GetYear function in Java Script returns four digits in internet explorer. It has only problem with Firefox

# re: GetYear Function in Java Script is not working properly in firefox

Tuesday, February 12, 2008 2:34 AM by Joe Chung

Firefox is following the ECMAScript specification (ECMA-262) by returning 107 for 2007, 10 for 2008, etc.  The specification indicates that the getYear() function should return the number of years since 1900.

So SpiderMonkey (Firefox's JavaScript) is doing right by the spec, and JScript (Internet Explorer's JavaScript) isn't.

In any case, getYear() is a deprecated function, and you should use getFullYear().

Leave a Comment

(required) 
(required) 
(optional)
(required)