Search code examples
javascriptphpjquerytimercountdown

jQuery.countdown issue on seconds countdown


i need a 24h SESSION countdown. im using the jQuery.countdown. This code below gives me a countdown of 12h why not 24h ? And if i set a range of 20 seconds or 10 the countdown says its done. anyone see the bug ?

 <?php 
    date_default_timezone_set('Europe/Berlin');
    $_SESSION['code_end'] = time() + 86400;
 ?>

 <div id="getting-started"></div>
 <script type="text/javascript">
    $("#getting-started").countdown("<?php echo date('Y/m/d h:i:s', $_SESSION['code_end']);?>")
       .on('update.countdown', function(event) {
          var format = '%H:%M:%S';
          if(event.offset.totalDays > 0) {
               format = '%-d day%!d ' + format;
          }
          if(event.offset.weeks > 0) {
               format = '%-w week%!w ' + format;
          }
          $(this).html(event.strftime(format));
     })
      .on('finish.countdown', function(event) {
        alert("session End");
        $(this).html('This offer has expired!')
               .parent().addClass('disabled');

    });
</script>

Solution

  • You need to give the countdown function a 24H format.

    Your code:

    $("#getting-started").countdown("<?php echo date('Y/m/d h:i:s', $_SESSION['code_end']);?>")
    

    needs to be:

    $("#getting-started").countdown("<?php echo date('Y/m/d H:i:s', $_SESSION['code_end']);?>")
    

    (capital H for 24H format)

    Have a working example here: https://www.seeque-secure.dk/demo.php?id=jQuery.countdown+issue+on+seconds+countdown