Skip to main content

Template: Countdown&up

<body>
  <div align=center>#placeholder</div>
  <div align=center id="up-1"></div>
  <div align=center>#placeholder</div>
  <script>
    function updateCountup(id) {
      var birthDay = new Date("12/31/2099 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 countupDisplay = document.getElementById(id);
      countupDisplay.innerHTML = days + " Days " + hours + " Hrs " + minutes + " Mins " + seconds + " Secs";
    }

    updateCountup('up-1'); // 初始页面加载时显示倒计时
    setInterval(function() { updateCountup('up-1'); }, 1000); // 每秒更新一次倒计时
  </script>
</body>
<body>
  <div align=center>#placeholder</div>
  <div align=center id="down-1"></div>
  <div align=center>#placeholder</div>
  <script>
    function updateCountdown(id) {
      var birthDay = new Date("01/01/2001 00:00:00");
      var today = new Date();
      var timeDiff = birthDay.getTime() - today.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('down-1'); // 初始页面加载时显示倒计时
    setInterval(function() { updateCountdown('down-1'); }, 1000); // 每秒更新一次倒计时
  </script>
</body>