|
January 8, 2000 The getYear() Method Tips: January 2000
Yehuda Shiran, Ph.D.
|
|
Is
the correct date? It is right only on Internet Explorer. Try viewing this tip in Netscape Navigator. The year will probably be 100. The two browsers differ in their interpretation of the getYear() method. Until Jan 1, 2000, the scripting community assumed that this method returns a number equal to the current year less 1900; that is, the last two digits of the year. However, for years greater than 1999, the getYear() method returns the full four-digit year. We used to believe that the following code segment prints the current four-digit year:
Now that we rolled over to year 2000, we can see that only Internet Explorer behaves as explained above. Netscape Navigator still computes the difference between the current year and 1900, as oppose to Internet Explorer that returns the full four digits for year 2000 and above. The easiest way out is to replace the Learn more about the Date object from Column 2, Mastering JavaScript Dates.
People who read this tip also read these tips: Look for similar tips by subject: |