Advertisement
MChaos

countdown

Jun 18th, 2025
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <div class="countdown_sale">
  2.                 <div class="sales-countdown">
  3.                     <div class="countdown_sale_info">
  4.                         <div id="countdown"></div>
  5.                         <div class="countdown_info">
  6.                             <span class="info_days"><?= DAYS ?></span>
  7.                             <span class="info_hours"><?= HOURS ?></span>
  8.                             <span class="info_minutes"><?= MINUTES ?></span>
  9.                             <span class="info_seconds"><?= SECONDS ?></span>
  10.                         </div>
  11.                     </div>
  12.                 </div>
  13.             </div>
  14.  
  15. <script src="/app/js/jquery.countdown.js"></script>
  16. <script>
  17.     $(function () {
  18.  
  19.         <?php
  20.         $startDate = new DateTime($sale->date);
  21.         $currentDate = new DateTime();
  22.         if ($startDate > $currentDate) {
  23.             $sale->date_end = $sale->date;
  24.         }
  25.         ?>
  26.  
  27.         var note = $('#note'),
  28.             <?php $date = new DateTime($sale->date_end); ?>
  29.             ts = new Date(<?=$date->format('Y')?>, <?=$date->format('m') - 1?>, <?=$date->format('d')?>),
  30.             newYear = true;
  31.  
  32.         if ((new Date()) > ts) {
  33.             // The new year is here! Count towards something else.
  34.             // Notice the *1000 at the end - time must be in milliseconds
  35.             ts = (new Date()).getTime() + 10 * 24 * 60 * 60 * 1000;
  36.             newYear = false;
  37.         }
  38.  
  39.         $('#countdown').countdown({
  40.             timestamp: ts,
  41.             callback: function (days, hours, minutes, seconds) {
  42.  
  43.                 var message = "";
  44.  
  45.                 message += days + " day" + (days == 1 ? '' : 's') + ", ";
  46.                 message += hours + " hour" + (hours == 1 ? '' : 's') + ", ";
  47.                 message += minutes + " minute" + (minutes == 1 ? '' : 's') + " and ";
  48.                 message += seconds + " second" + (seconds == 1 ? '' : 's') + " <br />";
  49.  
  50.                 if (newYear) {
  51.                     message += "left until the new year!";
  52.                 } else {
  53.                     message += "left to 10 days from now!";
  54.                 }
  55.  
  56.                 note.html(message);
  57.             }
  58.         });
  59.  
  60.     });
  61. </script>
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement