First I will show you what it will be for the particular browser you are now using. The table below displays information on your browser plus the results of the year() method on a date in 1998 and 2001. The two dates I used for this test was July 1, 1998 and July 1, 2001 (see lessons 8 and 10 if you need to review the date object and the navigator object). I used the years 1998 and 2001 for my testing because the years 1999 and 2000 each have three digits that are the same which makes it difficult to be certain that the 2 digit year is being extracted correctly.
So how do we compensate for this is our scripts. The solution is simple for browsers that have results that like shown for Netscape 4.5. All you need to do is add 1900 to either to get the 4 digit year.
Things are a little more complicated for the Internet Explorer 5 type browsers. This browser displays a 2 digit year prior to 2000 and a 4 digit year after that.
Here is a script that should work for all the browsers to return a 4
To display a 2 digit year, I first make the year variable a string and
then use the substring() method to get the last two digits.
Here is the results for 7/1/1998 and 7/1/2001 (same two dates I used in first paragraph)
4 and 2 digit year extracted from 7/1/1998:
I updated lessons 2, 8, 9, and 11 to make all of the scripts Y2K