Convert seconds to HH-MM-SS with JavaScript?

前端 未结 30 2436
南旧
南旧 2020-11-22 10:05

How can I convert seconds to an HH-MM-SS string using JavaScript?

30条回答
  •  不要未来只要你来
    2020-11-22 10:35

    I've used this code before to create a simple timespan object:

    function TimeSpan(time) {
    this.hours = 0;
    this.minutes = 0;
    this.seconds = 0;
    
    while(time >= 3600)
    {
        this.hours++;
        time -= 3600;
    }
    
    while(time >= 60)
    {
        this.minutes++;
        time -= 60;
    }
    
    this.seconds = time;
    }
    
    var timespan = new Timespan(3662);
    

提交回复
热议问题