About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets


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;

BackBack