Hi, I have been researching a few different js count down timer scripts. I need to display a simple timer that counts down from mid night. Some of the scripts that I found seem to be a few years old (but still seem to work fine). Can any of you JS experts recommend a good script to use as I would like to use something that is up to date, thanks in advance for your help
The easiest way to make a count Down Timer is by using jquery, there are a lot out there, just search for "jquery countdown".
try this.. <p><span id="the_time">00:00:00</span> till midnight</p> <script type="text/javascript"> function update_countdown() { var timedate_now = new Date(); var timedate_tom = new Date(); timedate_tom.setDate( timedate_now.getDate() + 1 ); timedate_tom.setHours(0); timedate_tom.setMinutes(0); timedate_tom.setSeconds(0); var diff = timedate_tom.getTime() - timedate_now.getTime(); var time_remaining = diff / 1000 / 60 / 60; // get hours remaining var hours = parseInt(time_remaining,10); // minutes remaining var mins_remaining = (time_remaining - hours) * 60; var mins = parseInt(mins_remaining,10); // seconds remaining var secs_remaining = (mins_remaining - mins) * 60; var secs = parseInt(secs_remaining, 10); document.getElementById("the_time").innerHTML = hours + ":" + mins + ":" + secs; setTimeout(update_countdown,500); } update_countdown(); </script> HTML:
Cool, thanks... quick question, if i want it to countdown to a midnight at a certain date in the future, for example, let's say it is for 1 weeks time, is it possible to display the days countdown first and then when it turns into the final day, display the hours:mins:secs So, 7 days away = 7 days 6 days away = 6 days 5 days away = 5 days 4 days away = 4 days 3 days away = 3 days 2 days away = 2 days 1 day away = 23:59:59 (and counting) is that possible or would i need to use 2 different types of scripts