On-line Guides

How To Guides






The JavaScript FAQ
Prev Home Next

Year 2000 Problem

Question: Is JavaScript code vulnerable to the Year 2000 problem?

Answer: You can write your code so as to make sure that it will not suffer from "millennium bugs" even if run on older browsers. However, without special precautions, JavaScript code can be vulnerable to the Year 2000 problem.

To avoid "millennium bugs", take into account the following:

  • in most browsers, the Date.getYear() method returns the full four-digit year for the year 2000 and all subsequent years
  • in some old browsers (for example, Internet Explorer 3.0) this method returns the year minus 1900 for all years.

The following code fragment sets the correct four-digit year in all browsers:

theDate = new Date();
theYear = theDate.getYear();
if (theYear<1900) theYear=theYear+1900;

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


Mirrored with kind permission of Alexei Kourbatov Design by Interspire

AltStyle によって変換されたページ (->オリジナル) /