main.js 1.0 KB

12345678910111213141516171819202122232425
  1. const SECONDS = 1000;
  2. const MINUTES = SECONDS * 60;
  3. const HOURS = MINUTES * 60;
  4. const DAYS = HOURS * 24;
  5. document.addEventListener("DOMContentLoaded", () => {
  6. setInterval(() => {
  7. const future_date = new Date("June 12, 2021 00:00:00").getTime();
  8. const now = new Date().getTime();
  9. const time_diff = future_date - now;
  10. const days_text = Math.floor(time_diff / DAYS).toString();
  11. const hours_text = Math.floor((time_diff % DAYS) / HOURS).toString();
  12. const minutes_text = Math.floor((time_diff % HOURS) / MINUTES).toString();
  13. const seconds_text = Math.floor((time_diff % MINUTES) / SECONDS).toString();
  14. document.querySelector("#counter__days").textContent = days_text;
  15. document.querySelector("#counter__hours").textContent = hours_text;
  16. document.querySelector("#counter__minutes").textContent = minutes_text;
  17. document.querySelector("#counter__seconds").textContent = seconds_text;
  18. }, 1000);
  19. });