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
https://forums.phpfreaks.com/topic/14637-countdown-timer-help/
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
https://forums.phpfreaks.com/topic/14637-countdown-timer-help/#findComment-59479
Share on other sites

Archived

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

×
×
  • 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.