format(seconds) { const H = Math.floor(seconds / 3600); let hour = H >= 10 ? H : '0' + H; seconds -= 3600 * H; const M = Math.floor(seconds / 60); let min = M >= 10 ? M : '0' + M; seconds -= 60 * M; let sec = seconds >= 10 ? seconds : '0' + seconds; if (hour === "00") { return min + ':' + sec; } else { return hour + ':' + min + ':' + sec; } }
针对方法做了一些修改,在计算的时候避免 和字符串做计算,否则在浏览器解析有可能报错
原方法链接:https://www.cnblogs.com/jwzhang/p/14324361.html