简体   繁体   English

如何让我的倒数计时器显示小时

[英]How can I make my countdown timer show hours

I'm looking for a quick change for a countdown timer a friend of mine once programmed.我正在寻找一个倒数计时器的快速更改,我的一个朋友曾经编程过。 He currently can't help me change or extend it, so I'm looking for some help from the friendly folks of stackoverflow.他目前无法帮助我更改或扩展它,所以我正在寻求 stackoverflow 友好人士的帮助。

So far the countdown shows: MM:SS:ss到目前为止倒计时显示: MM:SS:ss

I want to change it to: HH:MM:SS我想把它改成: HH:MM:SS

An idea how I can achieve this?一个想法如何实现这一目标? Many many thanks!非常感谢!

Here's my code:这是我的代码:

 function startTimer(duration, display) { var timer = duration, minutes, seconds, dispms; const intervalIndex = setInterval(function () { dispms=parseInt(timer % 100,10); seconds = parseInt(timer / 100, 10); minutes = parseInt(seconds / 60, 10); seconds = parseInt(seconds % 60, 10); minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; dispms = dispms < 10 ? "0" + dispms : dispms; display.textContent = minutes + ":" + seconds; if (--timer < 0) { clearInterval(intervalIndex); } }, 10);} window.onload = function () { var countdown = 60 * 60 * 100, display = document.querySelector('#time'); startTimer(countdown, display); };
 <div id="time"></div>

Try this:尝试这个:

 function startTimer(duration, display) { var timer = duration, minutes, seconds, dispms; const intervalIndex = setInterval(function () { seconds = parseInt(timer / 100, 10); minutes = parseInt(seconds / 60, 10); hours = parseInt(minutes / 60, 10); seconds = parseInt(seconds % 60, 10); minutes = parseInt(minutes % 60, 10); seconds = seconds < 10 ? "0" + seconds : seconds; minutes = minutes < 10 ? "0" + minutes : minutes; hours = hours < 10 ? "0" + hours : hours; display.textContent = hours + ":" + minutes + ":" + seconds; if (--timer < 0) { clearInterval(intervalIndex); } }, 10);} window.onload = function () { var countdown = 600500, display = document.querySelector('#time'); startTimer(countdown, display); };
 <div id="time"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM