JavaScript Clock Fix

Tip from: John

     It seems that some JavaScript clocks are off a month. Here may be the reason yours is. Thanks to John for offering us this quick fix:


     Hey, I was looking on your site to see if you might have anything I could use as a reference when I came across a script for displaying the date in numbers. There is a small problem with the script. The month will always be off by one with this method. In JavaScript the month values are 0-11 not 1-12, so you have to increment the month by 1.

     Here's how I overcame this in a script I wrote. You can use the document.write method to put the date on the page, or what I used it for, as a value for a textbox in a form.

<script language="JavaScript">
<!-- hide script
todaysDate = new Date();
today = todaysDate.getDate();
month = todaysDate.getMonth();
year = todaysDate.getYear();
theDate = ++month + "/" + today + "/" + year;
//end hiding -->
</script>

...Thanks, John.

Back to the Clocks, Calculators, and Calendar Scripts