javascript - 秒倒计时的 jQuery.countdown 问题

标签 javascript php jquery timer countdown

我需要 24 小时 SESSION 倒计时。我正在使用 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>

最佳答案

您需要为倒计时功能提供 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']);?>")

(大写 H 表示 24 小时格式)

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

关于javascript - 秒倒计时的 jQuery.countdown 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57082750/

相关文章:

javascript - Dropzone.js 与 Laravel 得到 500(内部服务器错误)

javascript - 如何避免在 XMLHttpRequest 调用后自动重新加载页面?

Php MySQL 查询在资源有限的托管中内存不足

php - "php_connect_nonb() failed: Operation now in progress (115)"间歇性发生

javascript - 切换图像在 jquery 中不起作用

javascript - jQuery UI 可排序连接列表 - 获取更改状态

javascript - JSON 和引用

php - 是否允许使用 HTMLPurifier 嵌入/对象/参数 HTML 标签?

javascript - jQuery Mobile 无法在 Android 设备上动态更改图像

javascript - Knockout - 根据 observableArray 检查复选框