I have a simple timer,onclick 'start Timer' button, timer will start and on click of 'pause' button it will pause.Till now it is working fine. Now I need to convert timer into hh:mm:ss format. like when it crossed 60, a minute will add left side,again when minute will cross 60,an hour will be added.I am not getting the concept how to do, can anyone please help me.Here is the code below and demo https://stackblitz.com/edit/angular-8wlwkj?file=src%2Fapp%2Fapp.component.ts
app.component.html
<hello name="{{ name }}"></hello>
<p>
Start editing to see some magic happen :)
</p>
<button (click)='startTimer()'>Start Timer</button>
<button (click)='pauseTimer()'>Pause</button>
<p>{{timeLeft}} Seconds</p>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 6';
timeLeft: number = 0;
interval;
startTimer() {
this.interval = setInterval(() => {
if(this.timeLeft > 0) {
this.timeLeft++;
} else {
this.timeLeft = 1;
}
},100)
}
pauseTimer() {
clearInterval(this.interval);
}
}