|
July 7, 2000 getFullYear() vs. getYear() Tips: July 2000
Yehuda Shiran, Ph.D.
|
|
Seems like the dilemma whether to use getFullYear() or getYear() is still not settled. As far as functionality is concerned, getFullYear() should be always used. It returns the full four-digit year, no matter if the date is before 2000, in 2000, or after 2000. Equally important is the fact that both browser return the same value for the getFullYear() method. The only caveat is the getFullYear() method has been added to the Date object some time later than the getYear() method. Therefore, some old browsers cannot interpret getFullYear(). But what's the problem with getYear()? It behaves differently on Internet Explorer than on Netscape Navigator. The following table summarizes the differences, by showing the returned values for two different years, 1998 and 2000:
But, if you check again the
People who read this tip also read these tips: Look for similar tips by subject: |