|
|
Q1037 Are there any Y2K date issues with JavaScript?
irt.org | Knowledge Base | JavaScript | Date | Q1037 [ previous next ] Q1037 Are there any Y2K date issues with JavaScript?Given a date object:
when retrieveing the year value using:
the date may be returned as 99 for the year 1999 and 2000 for the year 2000. For Y2K compliancy in Internet Explorer 4+ and Netscape Navigator 4+, you can use:
Which will always return a full four digit year. To ensure that all browsers behave the same, do this:
To simplify the process you could create a y2k() function that takes care of this for you:
There is another possible Y2K issue with the document objects lastModified property, where using the general y2k() function to return a full ccyy date may not work. From what I can make out document.lastModified may return a two digit date - possibly even after 1999, when it might return 00 for 2000 and 01 for 2001. Using y2k() would make these dates 1900 and 1901 - not what you want to happen. In which case you might want to try a combination of getFullYear() (where supported) and a check to see what side of an arbitary two digit year your date falls on:
Several servers send a non-standard value back as flastmod, which can result in a date of 1/1/1970 (plus or minus timezones.) A page containing SSI may return a flastmod of 0 from most unix servers since any data on the page will not necessarily match the flastmod and so the page is considered created on the fly. Weird results may occur on a Mac in Internet Explorer if the timezone is not set in the system. Feedback on 'Q1037 Are there any Y2K date issues with JavaScript?' |
-- div -->
|