Jump to content

countdown timer help


digitalgod

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...
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.