Jump to content

Archived

This topic is now archived and is closed to further replies.

digitalgod

countdown timer help

Recommended Posts

hey guys,

I've been trying to make a countdown timer to a specific time for everyday but so far I've been unsucessful, all I was able to accomplish is making a normal timer.

I need a script that can count down how much time there's left before it's 9pm and as soon as it's done it start all over again...

Share this post


Link to post
Share on other sites
something like this will help
[code]
<body onload="show_time();">
<script language="javascript">
function show_time(){
var today = new Date();
var time_dif = "";

if (today.getHours() > 8) var odt = new Date(today.getFullYear(), today.getMonth(), today.getDate()+1, 9, 0, 0);
else var odt = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 9, 0, 0);

var d_time = odt.getTime() - today.getTime();

var f_minutes = (d_time/1000)/60;
var i_minutes = Math.floor(f_minutes);
var seconds = parseInt((f_minutes - i_minutes) * 60);

var f_hours = i_minutes / 60;
var i_hours = Math.floor(f_hours);
var minutes = parseInt((f_hours - i_hours) * 60);

if (i_hours > 0) time_dif = i_hours + " hours, ";
if (minutes > 0) time_dif += minutes + " minutes ";
if (seconds > 0) time_dif += "and " + seconds + " seconds ";

time_dif += "until " + odt;

document.getElementById('time_div').innerHTML = time_dif;

}
setInterval("show_time()", 1000);
</script>
<div id="time_div">

</div>
</body>
[/code]

Share this post


Link to post
Share on other sites
thanks nogray but for some reason it keeps giving me the countdown for the day after, like right now it's almost 4pm and it tells me that there's 17 hours left before 9pm...

I can't seem to find what to change though... any clues?

Share this post


Link to post
Share on other sites
I set it up for 9am, you can change it to 9 bm by changing the 9 to 21 (military time) and the 8 to 20

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.