1 // 普通时间格式转成秒 2 var timeToSec = function (time) { 3 var timeArr = time.split(':') 4 var hour = timeArr[0] 5 var minute = timeArr[1] 6 var sec = timeArr[2] 7 8 return Number(hour * 3600) + Number(minute * 60) + Number(sec) 9 } 10 11 12 // 秒转为普通时间 13 var secToTime = function (s) { 14 var hour = parseInt(s / 3600) 15 var minute = parseInt((s - (hour * 3600)) / 60) 16 var sec = s - (hour * 3600) - (minute * 60) 17 18 var H = hour > 9 ? hour : '0' + hour 19 var M = minute > 9 ? minute : '0' + minute 20 var S = sec > 9 ? sec : '0' + sec 21 22 return H + ':' + M + ':' + S 23 }
来源:博客园
作者:Web初心
链接:https://www.cnblogs.com/web-xu/p/11769606.html