Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




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; Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next

  Mirrored with kind permission of Alexei Kourbatov Design by Interspire