# js实现时分秒的定时器

<p class="fr"><span class="time" id="time">02:11:10</span> 后竞猜截止</p>

js代码
/*倒计时start*/
var interval = 1000;
var leftSecond;
var time = $("#time").html(); var arr = time.split(":");//以冒号分组 var hour = arr[0]; var minutes = arr[1]; var second = arr[2]; var hLength = hour.length; var mLength = minutes.length; var sLength = second.length; if(hLength === 2){ if(hour.substring(0,1) === '0'){ hour = sub(hour); } } if(mLength === 2){ if(minutes.substring(0,1) === '0'){ minutes = sub(minutes); } } if(sLength === 2){ if(second.substring(0,1) === '0'){ second = sub(second); } } function sub(num){ return num.substring(1,2);//截取第二个位置的 } hour = parseInt(hour); minutes = parseInt(minutes); second = parseInt(second); leftSecond = hour*60*60 + minutes*60 + second; function showTime(h , m , s){ leftSecond --; if(leftSecond === 0){$("form").attr('action',"javascript:;")
}
var h = Math.floor(leftSecond/3600);
var m = Math.floor((leftSecond-h*3600)/60);
var s = Math.floor(leftSecond-h*3600 - m*60);
if(s < 10){
s = '0' + s;
}
if(m < 10){
m = '0' + m;
}
if(h < 10){
h = '0' + h;
}
\$("#time").html(h+":"+ m +":" + s);

}

window.setInterval(function(){
showTime(hour , minutes , second );
},interval)
/*倒计时end*/

06-14 35

12-01 9488

05-28 56

#### <em>时分秒</em>计时器

2018年07月13日 00:00

10-17 2826

02-09 1143

06-21 28

#### 时钟 <em>定时器</em>

2017年07月14日 00:00

#### Android Studio 写的<em>时分秒</em>计时器

2018年07月19日 00:00

09-14 854