0

嗨,这是我的代码,我只是想让它倒计时到每周的同一时间示例(星期三午夜)

function makeTimer() {

        var endTime = new Date("Dec 12, 2019 00:00:00");          
            endTime = (Date.parse(endTime) / 1000);

            var now = new Date();
            now = (Date.parse(now) / 1000);

            var timeLeft = endTime - now;

            var days = Math.floor(timeLeft / 86400); 
            var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
            var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
            var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
  
            if (hours < "10") { hours = "0" + hours; }
            if (minutes < "10") { minutes = "0" + minutes; }
            if (seconds < "10") { seconds = "0" + seconds; }

            $(".days").html(days + "<span class='mid'>Days</span><span class='top'>d</span>");
            $(".hours").html(hours + "<span class='mid'>Hours</span><span class='top'>h</span>");
            $(".minutes").html(minutes + "<span class='mid'>Minutes</span><span class='top'>m</span>");
            $(".seconds").html(seconds + "<span class='mid'>Seconds</span><span class='top'>s</span>");       

       if (timeLeft < 0) {
        clearInterval(makeTimer);
        $(".timer").hide();;
      }

    }

    setInterval(function() { makeTimer(); }, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="timer">
  <div class="days"></div>
  <div class="hours"></div>
  <div class="minutes"></div>
  <div class="seconds"></div>
</div>

4

0 回答 0