js formatesecond

function ShowSeconds( s ) {
        var fm = [
            // Math.floor(Math.floor(Math.floor(s/60)/60)/24)%24,      //DAYS
            Math.floor(Math.floor(s/60)/60)%60,                          //HOURS
            Math.floor(s/60)%60,                                                //MINUTES
            s%60                                                                      //SECONDS
        ];
        return $.map(fm,function(v,i) { return ( (v < 10) ? '0' : '' ) + v; }).join( ':' );
}

 

module.exports = function (s) {
    var parts = [ Math.floor(s / 60 % 60), Math.floor(s % 60) ].map(pad);
    if (s > 60 * 60) parts.unshift(Math.floor(s / 60 / 60));
    return parts.join(':');
};
function pad (n) { return n < 10 ? '0' + n : String(n) }

 

module.exports = function (str) { 
    var seconds = 0;
    var parts = str.split(':');
    for (var i = 0, len = parts.length; i < len; i++) {
        seconds += Number(parts[i]) * Math.pow(60, len - i - 1);
    }
    return seconds;
};

 

function ShowSeconds( s ) {
    var parts = [ Math.floor(s / 60 % 60), Math.floor(s % 60) ];
    if (s > 60 * 60) parts.unshift(Math.floor(s / 60 / 60));
    return parts.map(function(v) { return ( (v < 10) ? '0' : '' ) + v; }).join(':');


}

 

posted @ 2016-08-15 10:49  lianhuaren  阅读(39)  评论(0)    收藏  举报