时分秒特效00:20:08
2020-02-24 本文已影响0人
最好的自己_3d47
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);
}