Members
Technology Zones
IBM Learning Center
Articles
Hosted By
Info
|
Rated
Read 31,894 times
Downloads
Related Categories
Count Down
This code lets you count down the number of days to a specific date
Add the following code to a file named clock-js.asp. Then add the second set of code to a HTML file in the same folder and run it. Because the timer needs pictures to display numbers, you have to create some, or take the ones attached to this code. If you create them name them nmbr#.gif (0 – 9).
var nTime = new Date(2000, 8, 15, 3, 55, -3, 0);
var nTarget = Date.UTC(2001, 10, 29, 16, 47, 0, 0) + nTime.valueOf() - 968896375889;
Tick();
if (document.all)
window.setInterval('Tick()', 1000);
else
window.setTimeout('Tick()', 100);
function Tick()
{
var dNow = new Date();
nTime = nTarget - dNow.valueOf(); // milliseconds until target
if (nTime < 0) nTime = 0;
nTime = Math.floor(nTime / 1000); // seconds until target
Display(document.cdDay1, document.cdDay0, 86400); // seconds per day
Display(document.cdHour1, document.cdHour0, 3600); // seconds per hour
Display(document.cdMinute1, document.cdMinute0, 60); // seconds per minute
Display(document.cdSecond1, document.cdSecond0, 1); // seconds per second
if (document.layers)
window.setTimeout('Tick()', 100);
}
function Display(el1, el0, nDivisor)
{
var nOnes;
var nValue = (nTime - (nTime %= nDivisor)) / nDivisor;
el1.src = "nmbr" + (nValue - (nOnes = nValue % 10)) / 10 + ".gif";
el0.src = "nmbr" + nOnes + ".gif";
}
HTML Code
<Table>
<FORM NAME=CLOCK>
<tr valign="top">
<td align=center><b>Days</b></td>
<td> | </td>
<td align=center><b>Hours</b></td>
<td> | </td>
<td align=center><b>Minutes</b></td>
<td> | </td>
<td align=center><b>Seconds</b></td>
</tr>
<tr>
<td align=center><img name=cdDay1 src=""><img name=cdDay0 src=""></td>
<td> </td>
<td align=center><img name=cdHour1 src=""><img name=cdHour0 src=""></td>
<td> </td>
<td align=center><img name=cdMinute1 src=""><img name=cdMinute0 src=""></td>
<td> </td>
<td align=center><img name=cdSecond1 src=""><img name=cdSecond0 src=""></td>
</tr>
</form>
</table>
</div>
<script language="javascript" src="clock-js.asp"></script>
I am as a web developer for a small company, working for a small company. I work on banking websites and verious related projects.
by: Nick Avery
liserdarts@yahoo.com
Comments
Posted by liserdarts on 12 Oct 2002
Sorry for replying so late, I don’t exactly check these things so often. I took a look at the code, and I really can’t remember how to set up the date. So I spent a wile rewriting the first two lines.... -
Posted by mazda_racer on 10 Sep 2002
I am new to this. Can you tell me where I insert the date. For example, if I want to show the number of days until Christmas 2002?
Thanks.
|
Search
Code Samples
New Members
|