Cla*_*dix 40

来吧!你不需要jQuery来实现:-)这里有一个可能的片段:

function secondsTimeSpanToHMS(s) {
    var h = Math.floor(s/3600); //Get whole hours
    s -= h*3600;
    var m = Math.floor(s/60); //Get remaining minutes
    s -= m*60;
    return h+":"+(m < 10 ? '0'+m : m)+":"+(s < 10 ? '0'+s : s); //zero padding on minutes and seconds
}

secondsTimeSpanToHMS(125);
Run Code Online (Sandbox Code Playgroud)


小智 5

试试这段代码:

function getTime(seconds) {

    //a day contains 60 * 60 * 24 = 86400 seconds
    //an hour contains 60 * 60 = 3600 seconds
    //a minut contains 60 seconds
    //the amount of seconds we have left
    var leftover = seconds;

    //how many full days fits in the amount of leftover seconds
    var days = Math.floor(leftover / 86400);

    //how many seconds are left
    leftover = leftover - (days * 86400);

    //how many full hours fits in the amount of leftover seconds
    var hours = Math.floor(leftover / 3600);

    //how many seconds are left
    leftover = leftover - (hours * 3600);

    //how many minutes fits in the amount of leftover seconds
    var minutes = Math.floor(leftover / 60);

    //how many seconds are left
    leftover = leftover - (minutes * 60);
    document.write(days + ':' + hours + ':' + minutes + ':' + leftover);
}
Run Code Online (Sandbox Code Playgroud)

测试:

getTime(2490453);? //-> 28:19:47.55:2853
Run Code Online (Sandbox Code Playgroud)