var hour,minute,second,alltime;//时 分 秒
hour=minute=second=alltime=0;//初始化
var timer=null; //定时器
startTimekeeper()
function startTimekeeper(){
timer=setTimeout(function(){
timeKeeper();
setTimeout(startTimekeeper(),1000)
},1000)
}
function timeKeeper(){
alltime++;
hour=Math.floor(alltime/60/60);
minute=Math.floor(alltime/60%60);
second=Math.floor(alltime%60);
if(hour<10){
hour = "0" + hour;
}
if(minute<10){
minute = "0" + minute;
}
if(second<10){
second = "0" + second;
}
console.log(hour+':'+minute+':'+second);
}
网友评论