时分秒的形式:如“12:02:25”。
private formatTime(totalSeconds: number): string
{
let hours: number = this.rounding((totalSeconds / 3600));
let hh: string = (hours < 10 ? "0" + hours : hours).toString();
let minutes: number = this.rounding((totalSeconds - hours * 3600) / 60);
let mm: string = minutes < 10 ? "0" + minutes : minutes.toString();
let seconds: number = this.rounding(totalSeconds - hours * 3600 - minutes * 60);
let ss: string = seconds < 10 ? "0" + seconds : seconds.toString();
let num: string = hh + ":" + mm + ":" + ss;
return num;
}
private rounding(num: number): number
{
return Math.floor(num);
}
网友评论