to home page

BWRS
SEARCH

HOMETUTORIALSLINKSFORUMGLOSSARYNEWS
 
COOL TIPS >
COUNTDOWN   

How To Create Countdown
(and Up !!) Timers

Okay so we missed the year 2000 for this Cool tip !!

There were tons of countdown timers on the web for the millenium. You can use the same technology to make a countdown timer for any date (or count up) using java-script

Here's an example of a timer counting in days to the next millenium

And here's the code

<script language="JavaScript">
<!--//
today=new Date();
mill3=new Date ("Jan 01 3000 00:00:00");
days=(mill3-today)/86400000
days=Math.round(days);
document.write("Days until next Millenium: "
+ days);
//-->
</script>

 

Just place it where you want between the <body> tags.


(frontpage express users can insert using the add script function but just add the 3rd to 8th lines not the first and last 2 lines. If using composer just add the whole thing using add HTML)

Lets break this down

today=new Date();
defines a variable called today based on the PC clock time of the viewer in milliseconds
mill3=new Date ("Jan 01 3000 00:00:00");
defines a variable called mill3 based on the date of the year 3000
days=(mill3-now)/86400000
defines a variable called days by taking today away from mill3 (this gives a total in milliseconds) then dividing the answer by the number of milliseconds in a day (86400000)
days=Math.round(days);
rounds days up (so get an single figure rather than i.e. 6.5 days)
document.write("Days until next Millenium: "
+ days);
displays days preceeded by Days until next Millenium

The <!--// and //--> hide the script from non JavaScript enabled browsers

Altering this for another date is easy as is changing the units measured (work in milliseconds and replace 86400000 e.g. 3600000 for no of hours)

Now see if you can come up with a way to create this COUNT - UP TIMER
(clue change Math.round to Math.floor to round your days down)

Answer at bottom

 

The only problem is that times are dependant on viewer's computer clock (and that will include any daylight saving adjustments)

 

back to top

 

back to Index
BACK TO INDEX

 

ANSWER

<script>
<!--//
today=new Date();
mill2=new Date ("Jan 01 3000 00:00:00");
days=(today-mill2)/86400000
days=Math.floor(days);
document.write("Days since year 2000: " + days);
//-->
</script>