Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <div id="countdown-timer"
  2. data-time="<?php echo $bus->getStartDateTime()->format('M d, Y H:i:s'); ?>" >
  3.  
  4. var countdownTimer = $("#countdown-timer"),
  5. countDownDate = new Date(countdownTimer.data('time')).getTime();
  6.  
  7. var intervalId = setInterval(function() {
  8.  
  9. var now = new Date().getTime();
  10. var distance = countDownDate - now;
  11.  
  12. var days = Math.floor(distance / (1000 * 60 * 60 * 24)),
  13. hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
  14. minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)),
  15. seconds = Math.floor((distance % (1000 * 60)) / 1000);
  16.  
  17. var remainingTime;
  18.  
  19. var formatTime = function (count, label) {
  20. return "<span>" + count + "</span> <sub>" + _t(label) + ".</sub>"
  21. }
  22.  
  23. if (days > 0) {
  24. remainingTime = formatTime(days, 'd') + ' ' + formatTime(hours, 'h') + ' ' + formatTime(minutes, 'm');
  25. } else if (days === 0 && hours !== 0 && minutes !== 0) {
  26. remainingTime = formatTime(hours, 'h') + ' ' + formatTime(minutes, 'm') + ' ' + formatTime(seconds, 's');
  27. } else if (days === 0 && hours === 0 && minutes !== 0) {
  28. remainingTime = formatTime(minutes, 'm') + ' ' + formatTime(seconds, 's');
  29. } else if (days === 0 && hours === 0 && minutes === 0) {
  30. remainingTime = formatTime(seconds, 's');
  31. } else {
  32. clearInterval(intervalId);
  33. remainingTime = '<div class="countdown-timer">' + formatTime(0, 'h') + ' ' + formatTime(0, 'm') + '</div>';
  34. }
  35.  
  36. $('#countdown-timer').html(function() {
  37. $('#countdown-timer span.nbsp').remove();
  38. return remainingTime;
  39. });
  40.  
  41. }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement