DotNetJaps

For the ASP.NET,By the ASP.NET and Of the ASP.NET

Sponsors

News


My Another Blog

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...

Comments

Joost Aarts said:

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

# February 11, 2008 5:47 AM

Jalpesh P. Vadgama said:

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

# February 12, 2008 12:04 AM

Joe Chung said:

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().

# February 12, 2008 2:34 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)