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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow

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:


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark