Skip to main content

Countdown

<body>
  <div align=center>#placeholder</div>
  <div align=center id="countdown-1"></div>
  <div align=center>#placeholder</div>
  <script>
    function updateCountdown(id) {
      var birthDay = new Date("01/21/2021 00:00:00");
      var today = new Date();
      var timeDiff = today.getTime() - birthDay.getTime();

      var seconds = Math.floor(timeDiff / 1000) % 60;
      var minutes = Math.floor(timeDiff / (1000 * 60)) % 60;
      var hours = Math.floor(timeDiff / (1000 * 60 * 60)) % 24;
      var days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));

      var countdownDisplay = document.getElementById(id);
      countdownDisplay.innerHTML = days + " Days " + hours + " Hrs " + minutes + " Mins " + seconds + " Secs";
    }

    updateCountdown('countdown-1'); // 初始页面加载时显示倒计时
    setInterval(function() { updateCountdown('countdown-1'); }, 1000); // 每秒更新一次倒计时
  </script>
</body>