function countdown()
{
seconds = 1000;
delay = delay-seconds;
conversion = Math.ceil(delay / seconds );
document.getElementById('timer').innerHTML = conversion + ":seconds until alarm goes off";
t3 = setTimeout("countdown()",1000);
if(conversion == 0)
{
alert('Wake UP!!!');
DontDoIt();
}
}
此代码以秒为单位显示计时器。如果时间大于60,我希望能够以分钟和秒显示时间。
我希望能够在数小时,分钟和秒钟内完成此操作
答案 0 :(得分:0)
这应该可以解决您的问题 如果需要,它会显示小时,分钟(前导零)和秒
function countdown() {
seconds = 1000;
delay = delay - seconds
secs = Math.ceil(delay / seconds);
var hrs = Math.floor(secs / 3600);
var mins = Math.floor((secs - (hrs * 3600)) / 60);
secs -= ((hrs * 3600) + (mins * 60));
document.getElementById('timer').innerHTML = ((hrs>0) ? hrs + ':' : '') + ((mins>0) ? ((mins>9) ? mins : '0'+mins) + ':' : '') + ((secs>9) ? secs : '0'+secs) + " until alarm goes off";
t3 = setTimeout("countdown()", 1000);
if (delay == 0) {
alert('Wake UP!!!');
DontDoIt();
}
}