January 8, 2000 - The getYear() Method
January 8, 2000 The getYear() Method Tips: January 2000
Yehuda Shiran, Ph.D.
|
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:
document.write((current.getYear() < 100) ? "19" : "", -->
current.getYear());
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 getYear()
method with the getFullYear()
method. So here is the new date:
.
Learn more about the Date object from Column 2, Mastering JavaScript Dates.