spacer
Yehuda Shiran January 8, 2000
The getYear() Method
Tips: January 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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:

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.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business