首页 > 解决方案 > jQuery.countdown 秒倒计时问题

问题描述

我需要 24 小时会话倒计时。我正在使用 jQuery.countdown。下面的这段代码给了我 12 小时的倒计时,为什么不是 24 小时?如果我将范围设置为 20 秒或 10 秒,则倒计时表示已完成。有人看到这个错误吗?

 <?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>

标签: javascriptphpjquerytimercountdown

解决方案


您需要为倒计时功能提供 24 小时格式。

你的代码:

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

需要是:

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

(24H 格式的大写 H)

这里有一个工作示例:https ://www.seeque-secure.dk/demo.php?id=jQuery.countdown+issue+on+seconds+countdown


推荐阅读