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 may be vulnerable to the Year 2000 problem.

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

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;
Better yet, instead of Date.getYear() use the the Date.getFullYear() method. It is supported in all modern browsers – and consistently returns the four-digit year.

Copyright © 1999-2011, JavaScripter.net.