如何用JavaScript将秒转换为HH-MM-SS?
要将秒转换为带有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>热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志