Menu
Hello, I am trying to create a countdown clock to indicate when a webcast begins. It starts at 18:00:00 UTC everyday, and I am comparing this time with the current time UTC. This then sets the timer. I have got an algorithm and coded it, but it doesn’t work, and I can’t debug it. Any help appreciated.
I will follow this post with the algorithm.
<title>Countdown</title>
<script language="javascript" type="text/javascript">
//Calculates Time Remaining Until Next Broadcast
//Defines And Converts Start Time UTC to Seconds
var StartTimeUTC = new Date();
var STHours = StartTimeUTC.setHours(18);
var STMinutes = StartTimeUTC.setMinutes(0);
var STSeconds = StartTimeUTC.setSeconds(0);
var STHoursInSeconds = ((parseInt(STHours) * 60) * 60);
var STMinutesInSeconds = (parseInt(STMinutes) * 60);
var StartSecondsUTC = (parseInt(STHoursInSeconds) + parseInt(STMinutesInSeconds) + parseInt(STSeconds));
//Converts Current UTC to Seconds
var UTCNow = new Date();
var UTHours = UTCNow.getUTCHours;
var UTMinutes = UTCNow.getUTCMinutes;
var UTSeconds = UTCNow.getUTCSeconds;
var UTHoursInSeconds = ((parseInt(UTHours) * 60) * 60);
var UTMinutesInSeconds = (parseInt(UTMinutes) * 60);
var UTCNowSeconds = (parseInt(UTHoursInSeconds) + parseInt(UTMinutesInSeconds) + parseInt(UTSeconds));
//Calculates Time Difference Between Start And Current Time
var SecondsDifference = parseInt(StartSecondsUTC) - parseInt(UTCNowSeconds);
var TimeToGoSeconds;
if (SecondsDifference < 0); //This Resets The Timer Every 24Hrs! (86400 is the number of seconds in a day)
{
TimeToGoSeconds = (86400 + parseInt(SecondsDifference));
}
else
{
TimeToGoSeconds = SecondsDifference;
}
//Re-Converts Time To Go Into HH:MM:SS
var ReturnToTime = new Date()
ReturnToTime.setSeconds(TimeToGoSeconds);
var DisplayHours = ReturnToTime.getHours();
var DisplayMinutes = ReturnToTime.getMinutes();
var DisplaySeconds = ReturnToTime.getSeconds();
if (DisplayHours < 10)
{
DisplayHours = "0" + DisplayHours;
}
if (DisplayMinutes < 10)
{
DisplayMinutes = "0" + DisplayMinutes;
}
if (DisplaySeconds < 10)
{
DisplaySeconds = "0" + DisplaySeconds;
}
var TimeRemainingString = ("Time Until Next Broadcast; " + DisplayHours + ":" + DisplayMinutes + ":" + DisplaySeconds);
</script>
document.write("STHours Reads " + STHours);
document.write("STMinutes Reads " + STMinutes);
document.write("STSeconds Reads " + STSeconds);
document.write("UTHours Reads " + UTHours);
document.write("UTMinutes Reads " + UTMinutes);
document.write("UTMinutes Reads " + UTMinutes);
document.write("StartSecondsUTC Reads " + StartSecondsUTC);
document.write("UTCNowSeconds Reads " + UTCNowSeconds);
document.write("SecondsDifference Reads " + SecondsDifference);
document.write("TimeToGoSeconds Reads " + TimeToGoSeconds);
document.write("TimeRemainingString Reads " + TimeRemainingString);
</script>
[code=php]
<html>
<HEAD>
<title>countdown</title>
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
function getTime() {
now = new Date();
TZ = 0; // TZ = now.getTimezoneOffset()/60;
mm = now.getMonth();
dd = now.getDate();
yy = now.getFullYear();
later = new Date(yy,mm,(dd+1),(18+TZ),0,0,0); // later = Date.UTC(yy,mm,(dd+1),18,0,0,0);
days = (later - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
if (daysRound < 0) { daysRound += 1; }
hours = (later - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (later - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
if (minutesRound < 10) { minutesRound = '0'+minutesRound; }
seconds = (later - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if (secondsRound < 10) { secondsRound = '0'+secondsRound; }
var str = '';
// str += daysRound+':';
str += hoursRound+':'+minutesRound+':'+secondsRound;
document.getElementById('TimeLeft').innerHTML = '<h4>(Hours : Minutes : Seconds)<br>Show time in: '+str+'</h4>';
newtime = setTimeout("getTime();", 1000);
}
</script>
</HEAD>
<BODY onLoad="getTime()">
<div id="TimeLeft" align="center">
<h4>(Hours : Minutes : Seconds)</h4>
</div>
</body>
</html>
[/code]
... (currently not on Daylight Saving)...[/quote]
function getCountdown()
{
var CountdownString;
Now = new Date();
TZ = 0;
mm = Now.getMonth();
dd = Now.getDate();
yy = Now.getFullYear();
Start = Date.UTC(yy,mm,(dd+1),18,0,0,0);
days = (Start - Now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
if (daysRound < 0)
{
daysRound += 1;
}
hours = (Start - Now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
if (hoursRound < 10)
{
hoursRound= '0'+ hoursRound;
}
minutes = (Start - Now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
if (minutesRound < 10)
{
minutesRound = '0'+ minutesRound;
}
seconds = (Start - Now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if (secondsRound < 10)
{
secondsRound = '0' + secondsRound;
}
if ( hoursRound >= 16 && hoursRound < 24 )
{
CountdownString = ("Broadcasting Now!");
}
else
{
CountdownString = ("Next Webcast Starts In: " + hoursRound + ":" + minutesRound + ":" + secondsRound + " Hrs");
}
document.getElementById('Countdown').innerHTML = CountdownString;
newtime = setTimeout("getCountdown();", 1000);
}
0.1.9 — BETA 6.18