要将秒转换为带有JavaScript的HH-MM-SS,请尝试运行以下代码-
<html> <head> <title>JavaScript Dates</title> </head> <body> <div id = "newSeconds"></div> <script> var convertSeconds = function(sec) { var hrs = Math.floor(sec / 3600); var min = Math.floor((sec - (hrs * 3600)) / 60); var seconds = sec - (hrs * 3600) - (min * 60); seconds = Math.round(seconds * 100) / 100 var result = (hrs < 10 ? "0" + hrs : hrs); result += "-" + (min < 10 ? "0" + min : min); result += "-" + (seconds < 10 ? "0" + seconds : seconds); return result; } var add_seconds = convertSeconds(100); document.getElementById("newSeconds").innerHTML = add_seconds; </script> </body> </html>