Get Year Of Date Object Using Javascript

I was fooling around with the Date object in Javascript and I had problems getting the year. I was confused why instead of the year 2009, 109 was always returned. Seems this case is browser dependent. The value returned by getYear() is not always four digits. Between 1900 and 1999 the year returned is only two digits.

For years before 1900 and after 1999 the return is browsers dependent.

Internet Explorer – returns four digits for years before 1900 and after 1999.

Mozilla/Firefox – it returns a value of 100 or greater for years >= 2000. In my case, instead of the year 2009, 109 was returned.

There is a separate function to get the correct year called getFullYear(). Use that and you should be just fine.

Related Posts Plugin for WordPress, Blogger...

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *