我有一個秒錶,它工作良好,但在60秒後秒值我需要計時器去零和最小1,並以同樣的方式每60秒鐘應該改變創建一個秒錶與錯誤
/* Stopwatch */
starttime(){
console.log("timer started");
if(this.running == 0){
this.running = 1;
this.adder()
}else{
this.running = 0;
}
}
reset(){
console.log("timer reset");
this.running = 0;
this.time = 0;
this.total = 0;
this.Sec = 0;
}
adder(){
console.log("timer incrementor");
if(this.running == 1){
setTimeout(()=>{
this.time++;
var mins = Math.floor(this.time/10/60);
var sec = Math.floor(this.time/10);
var tens = this.time/10;
this.total = mins + ':' + sec;
console.log(this.total) ;
this.Sec = sec;
this.adder()
},10)
}
}
但這裏時間的變化,仲被添加了,當它到達60它移動到61,62,63並不變爲零後.... 120秒採樣時間是0:2:120 ,我需要的是0:2:0(hrs:sec:min)
修改'var sec = Math.floor(this.time/10)%60;並改變設置超時時間到
this.adder()
},100)
雅這個工作,但我覺得我的計時器努力快,我比我的定時器,秒錶在我的手機,當mytimer在20秒移動定時器爲:15SE –
我改變了設置的超時時間爲100首先它在10工作很好謝謝你的答案%60 –
你能告訴我怎麼能把這個狀態00:00到我的計時器任何建議@reza –