angular常用过滤器---秒转时分秒

filter("seconds_to_hhmmss", function() {
    return function(seconds) {
        if (seconds || seconds === 0) {
            var seconds = Number(seconds);
            var hh = (seconds / 3600) >= 1 ? Math.floor(seconds / 3600) : 0;
            var mm = ((seconds - hh * 3600) / 60) >= 1 ? Math.floor((seconds - hh * 3600) / 60) : 0;
            var ss = seconds - hh * 3600 - mm * 60;
            if (hh > 99) {
                return hh + ':' + padding(mm, 2, '0') + ':' + padding(ss, 2, '0');
            }
            return padding(hh, 2, '0') + ':' + padding(mm, 2, '0') + ':' + padding(ss, 2, '0');
        } else {
            return '——';
        }
    }
})

用法

<div> {{item.start_time | seconds_to_hhmmss}} </div>

猜你喜欢

转载自blog.csdn.net/lunhui1994_/article/details/80751260