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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint