Home
About TLCC
Course Catalog
Register/Update Account
FREE Course! Get Started!
Contact TLCC

Click here to get live help!

Y2K JavaScript Problem

Some browsers will return different values for the getYear method. This will create problems depending on the browser your users are using. The most recent versions of these browsers (Netscape 4.5 and higher, Internet Explorer 4.0 and higher) return the following:
  • Netscape will return current year minus 1900. If the year is 1999, Netscape will return 99, if the year is 2000, Netscape will return 100, etc.
  • Internet Explorer will return current year minus 1900 ONLY FOR YEARS IN 19xx, OTHERWISE it returns a 4 digit year. So, 1999 will return 99, but 2000 will return 2000.

    To correct for this problem, use the following code:

    currentdate = new Date();
    tempyear = currentdate.getYear();
    year = tempyear<1000 ? tempyear + 1900 : tempyear

    The reason this works is as follows:

    If tempyear is a two digit year or a three digit year then the condition is true and 1900 is added to the value returned by the getYear method. If the year returned in 99, then 1900 and 99 equals 1999. If the year is 100, then 1900 and 100 equals 2000, so that will be fine.

    If tempyear is a four digit year than it will be greater than 1000, so just return whatever getYear returned.

    To see what your browser returns using the getYear method for the current date, click the button below:


    The code in the above button is:

    currentdate = new Date();
    tempyear = currentdate.getYear();
    alert (tempyear);

    The button below uses the fix listed above to correctly report the year using four digits for both Internet Explorer and Netscape:


    The code in the above button is:

    currentdate = new Date();
    tempyear = currentdate.getYear();
    year = tempyear < 1000 ?
    tempyear + 1900 :
    tempyear;
    alert (year);

    You should carefully review all your JavaScript code and determine if the getYear method has been used. If so, you should consider changing your code as needed.

    TLCC has provided updated information in both of our JavaScript courses. Current students can replicate the schedule database to get the updates. TLCC will update the downloadable versions of both courses by January 6, 2000. After that date, current students can download the course installation database and re-install the course to get the latest updates.

    (As a service to our students, TLCC is reporting the following information. This information has not been fully tested on all versions of Internet browsers and should be used only after you have tested all versions of browsers with your code.)







Copyright - The Learning Continuum Company, Ltd.