You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

4 years ago
  1. (function ($) {
  2. "use strict";
  3. function getTimeRemaining(endtime) {
  4. var t = Date.parse(endtime) - Date.parse(new Date());
  5. var seconds = Math.floor((t / 1000) % 60);
  6. var minutes = Math.floor((t / 1000 / 60) % 60);
  7. var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
  8. var days = Math.floor(t / (1000 * 60 * 60 * 24));
  9. return {
  10. 'total': t,
  11. 'days': days,
  12. 'hours': hours,
  13. 'minutes': minutes,
  14. 'seconds': seconds
  15. };
  16. }
  17. function initializeClock(id, endtime) {
  18. var daysSpan = $('.days');
  19. var hoursSpan = $('.hours');
  20. var minutesSpan = $('.minutes');
  21. var secondsSpan = $('.seconds');
  22. function updateClock() {
  23. var t = getTimeRemaining(endtime);
  24. daysSpan.html(t.days);
  25. hoursSpan.html(('0' + t.hours).slice(-2));
  26. minutesSpan.html(('0' + t.minutes).slice(-2));
  27. secondsSpan.html(('0' + t.seconds).slice(-2))
  28. if (t.total <= 0) {
  29. clearInterval(timeinterval);
  30. }
  31. }
  32. updateClock();
  33. var timeinterval = setInterval(updateClock, 1000);
  34. }
  35. var deadline = new Date(Date.parse(new Date()) + 25 * 24 * 60 * 60 * 1000 + 13 * 60 * 60 * 1000);
  36. initializeClock('clockdiv', deadline);
  37. })(jQuery);