js 秒数转时间格式

var a=[193,201,190,126,127,128]
for(var i in a){
    console.log(i2s(a[i]));
}

function i2s(ss) {
    var hh=mm=0;
    var ss = ~~ss;//
    if(ss>3599){
        hh=Math.floor(ss/3600);
        mm=Math.floor(ss%3600/60);
        ss=ss%60;
        return (hh>9?hh:'0'+hh)+":"+(mm>9?mm:'0'+mm)+":"+(ss>9?ss:'0'+ss);
    }else if(ss>59){
        mm=Math.floor(ss/60);
        ss=ss%60;
        return "00:"+(mm>9?mm:'0'+mm)+":"+(ss>9?ss:'0'+ss);
    }else{
        return "00:00:"+(ss>9?ss:'0'+ss);
    }
}

 

posted on 2021-01-04 14:18  神奇的旋风  阅读(1042)  评论(0编辑  收藏  举报

导航