美文网首页
CocosCreator中,以时分秒的形式显示秒数

CocosCreator中,以时分秒的形式显示秒数

作者: 全新的饭 | 来源:发表于2022-09-27 16:51 被阅读0次

时分秒的形式:如“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);
    }

相关文章

网友评论

      本文标题:CocosCreator中,以时分秒的形式显示秒数

      本文链接:https://www.haomeiwen.com/subject/wsafartx.html