我正在尝试计算设置的日期时间对象和当前时间之间经过的时间。我希望它能够以这种格式出现 DD:HH:MM:SS 其中 DD 是天,HH 是小时,MM 是分钟,SS 是秒。我能够得到总天数、总小时数、总分钟数和总秒数,但我不确定如何按照我想要的方式对其进行格式化。请帮忙
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>timer</title>
</head>
<body >
<div id ="time" name ="timer"></div>
<script>
var myVar = setInterval(myTimer, 1000);
function myTimer() {
let seconds = 1000 ;
let minutes = seconds * 60;
let hours = minutes * 60;
let days = hours * 24;
let years = days * 365;
const startDateTime = new Date("June 2, 2019 12:36:10 AM");
const newDateTime = new Date();
let timeDiff = newDateTime - startDateTime;
let totalSeconds = Math.round(timeDiff/seconds);
document.getElementById("time").innerHTML = totalSeconds;
}
</script>
</body>
</html>
慕容森
相关分类