Basically I'm any good at javascript and I would like a better countdown timer for my project. At the moment my timer looks something like this:
01:25:05
I would like it to look like this:
1 hour, 25 minutes and 5 seconds
But I also want it to be clever. So if its just 25 minutes it will say:
25 minutes.
This is my current javascript code:
function secondCountdown(){
if(typeof(skip) == "undefined"){
skip = "set";
} else {
var timeleft = document.getElementById("timeleft").innerHTML;
var time_split = timeleft.split(":");
if(parseInt(time_split[0]) < 10){
time_split[0] = time_split[0].charAt(1);
}
if(parseInt(time_split[1]) < 10){
time_split[1] = time_split[1].charAt(1);
}
if(parseInt(time_split[2]) < 10){
time_split[2] = time_split[2].charAt(1);
}
seconds = parseInt(time_split[2]) + parseInt(time_split[1]*60) + parseInt(time_split[0]*3600);
seconds -= 1;
if(seconds > 0){
var hours= Math.floor(seconds/3600);
seconds %= 3600;
var minutes = Math.floor(seconds/60);
seconds %= 60;
var timeleft = ((hours < 10) ? "0" : "") + hours + ":" + ((minutes < 10) ? "0" : "") + minutes + ":" + ((seconds < 10) ? "0" : "") + seconds;
document.getElementById("timeleft").innerHTML = timeleft;
} else {
document.getElementById("timeleft").innerHTML = "";
window.location='test.php?pageid=' + getURLParam("pageid");
return false;
}
}
setTimeout("secondCountdown()",1000);
}
window.onload = secondCountdown;
Maybe someone could edit it for me to make it output what I want?
Edit:
This is the PHP side of the timer.
<span id="timeleft">
$master = $timer['gta_time'] - time();
echo date( "00:i:s", $timer['gta_time'] - time() );
</span>