在網上找了很多都很復雜,看的暈頭轉向的,不過找到了簡介版的,先記錄下
var s = 23886; //需要轉的秒數 var m; setInterval(function(){ m = secondToDate(s) console.log(m) s--; },1000) // 輸出03:05:59 時分秒 function secondToDate(result) { var h = Math.floor(result / 3600) < 10 ? '0'+Math.floor(result / 3600) : Math.floor(result / 3600); var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60)); var s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60)); return result = h + ":" + m + ":" + s; }
輸出