More 103

Posted on April 09, 2003 @ 13:07 in General

Screenshot showing year as 103 rather than 2003Humbug. The lovely Unlimited Lives uses a browser sniffing javascript to display the current date on its website, but the script doesn't sniff anything other than Internet Explorer or Netscape, so if you use another browser, you're supposed to be living in the year 103. It's really just a minor thing, but it annoys me. So here are two ways to sidestep two-digit only year reporting and Y2k bugs:

Javascript
This is a little, non-browser sniffing script that works well for me:

function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function getCorrectedYear(year) {
year = year - 0;
if (year < 70) return (2000 + year);
if (year < 1900) return (1900 + year);
return year;
}
var dateError = new Date(document.lastModified);
var date = new Date(getCorrectedYear(dateError.getYear()),dateError.getMonth(),dateError.getDate());
document.write(y2k(date.getYear()));

PHP
However, I find it much easier to use the PHP capabilities of my webserver, by using this little statement:

<-?-php putenv("TZ=Europe/Amsterdam"); echo date("Y"); -?->

(Note the extra inserted hyphens for keeping the server from executing)

Hope that helps :-)

Comments and Trackbacks

No comments or trackbacks for this entry yet.

Post a comment

Comments and trackbacks have been closed on this site. My apologies.

Since MT-Blacklist inexplicably stopped working I had no other recourse than close comments and trackbacks to stop the spam. I've been meaning to correct this for quite a while, but life got in the way... in a good way I should add.