我为测验模块制作了一个倒计时时钟,所以每当计数器结束时,我都会得到一个负值。计时器结束后,我得到 -1 :-1 并且我希望它是 00:00。我以为总时间会有错误,但我无法弄清楚错误
我试过这个逻辑,但它不起作用
<script>
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function initializeClock(id, endtime) {
var clock = …Run Code Online (Sandbox Code Playgroud)