The JavaScript Source - Cut and Paste JavaScript Library
Y2K Center







e-Newsletters
Javascripts Weekly
Newsletter!
Text    HTML
Developer Channel
FlashKit
HierMenusCentral
JavaScript.com
JavaScript Source
Jobs.WebDeveloper.com
JustSmil
ScriptSearch
StreamingMedia
Web Hosts
WDJ
WDVL
WebDeveloper.com
WebReference.com
XML Files

find a web host with:
CGI Capabilities
MySQL
Windows Hosting
Unix Hosting
Telnet/SSH
Sun Solaris
advanced search
internet.com
Internet News
Internet Investing
Internet Technology
Windows Internet Tech.
Linux/Open Source
Web Developer
ECommerce/Marketing
ISP Resources
ASP Resources
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertising Info
Corporate Info

internet.commerce
Be a Commerce Partner


















Well, Y2K finally arrived and the world didn't come to an end, no nuclear missiles went off, and the stock market didn't crash. One thing that you might have not noticed is that some date-related JavaScripts have unnoticeably fallen prey to the Y2K bug. Go ahead and check your Web site to see how any date-related scripts are doing...

Back? Good. Bad News? Ok, it's happened to us all. Now, let's fix it.

I've included a short example program and have dissected it line by line .... Read on:

<script language="JavaScript">
This line tells the browser it is beginning a JavaScript code section.

// Begin
This line is pretty much standard in all JavaScripts - it tell 'ancient' browsers that don't support JavaScript to ignore the following script.
when = new Date();
This line set the day variable to a new Date. Since Date() has no parameters -- nothing inside the parenthesis -- the default date is set to the exact moment the script is loaded.
day = when.getDate();
This statement extracts the current day of the month, for example the 3 in January 3, 2000
year = when.getYear();
And, this line will extract the current year correctly as 19xx for years less than 2000, but reads 100 for 2000. Netscape's getFullYear() function attempts to work-around this, but here's a easier and more reliable solution until the getFullYear() function is supported by all major browsers....
if (year < 2000)
year = year + 1900;
If the year is read correctly as 2000 (or more) in the browser, everything is ok and the next line is ignored. If, however, the browser reads 100 instead, the if statement evaluates to true (100 < 2000 "100 is less than 2000") and the next line ads 1900 to it, to make it 2000. year equals year plus 1900, (100 + 1900 = 2000) then you can have any
document.write(year);
statements you want, etc here. And, the year will be Y2K compatible! Then, you finish the script tags, like this....
// End -->
</script>
That's all there is to writing Y2K compatible scripts. Good luck! And, check back to The JavaScript Source often for script updates.


[an error occurred while processing this directive]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs