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;

if (document.all)
   window.setInterval('Tick()', 1000);
   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";


   <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>
       <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>
<script language="javascript" src="clock-js.asp"></script>

You might also like...


Nick Avery I am as a web developer for a small company, working for a small company. I work on banking websites and verious related projects.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor