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>