I somehow copied this code from stackoverflow, but I forgot the link. I noticed that if I try to input hours, this will be converted into minutes which is very odd to look.
var hms = "02:30:00";
var a = hms.split(':'); // split it at the colons
// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
if(seconds > 0)
{
function secondPassed() {
var minutes = Math.round((seconds - 30)/60),
remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = ":" +minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
//form1 is your form name
document.form_quiz.submit();
} else {
seconds--;
}
}
var countdownTimer = setInterval('secondPassed()', 1000);
}
time{
color:red;
}
02:30:00 <br>
<time id="countdown">02:30:00</time>
The countdown should display like 02:29:59 after ( 1 second passes ). and not 149:59.