javascript - 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>
解决方案
您需要为倒计时功能提供 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
推荐阅读
- python - 如何将最小绝对回归实现为线性优化问题
- unity3d - 在 Unity 2D 中指定可步行区域
- python-3.x - Lightgbm 中的单调约束
- python - Pypi ics 中的访问属性
- mongodb - Spark Mongo 连接器,MongoShardedPartitioner 不起作用
- nativescript - 如何使用 Nativescript 跨平台创建具有相同外观和感觉的应用程序
- sql - 选择查询帮助更新
- android - Android:在另一个 JSON 数组中解析 JSON 数组
- visual-studio - 打开 Visual Studio 2017 时出现未知错误
- javascript - Sequelize 模型关联更新未按预期反映