<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>动态显示时间</title>
<script src="jquery-3.3.1.min.js"></script>
<style type="text/css">
#times{
width: 200px;
height: 20px;
border: 3px solid gray; /*如果不加实线无法显示边框*/
}
</style>
</head>
<body>
<span class="time"></span>时
<span class="second"></span>分
<script type="text/javascript">
var creatTime = new Date('2019-06-27 17:28:00').getTime() / 1000; // 订单创建时的时间戳
var date = Math.round(new Date() / 1000); //当前时间戳,单位:时间戳
var t = 60-parseInt((date - creatTime)/60); //ctime为订单创建的时间戳,t为订单待支付的剩下的时间,单位:分钟 剩余的分钟数
var s = 60 - parseInt(((new Date()/1000) - creatTime)%60) //剩余支付时间的秒数
console.log(creatTime);
console.log(date);
console.log(t);
console.log(s);
if (t <= 0 ) {
console.log('订单超时,自动关闭')
} else{
daojishi(creatTime);
}
//定义倒计时方法
function daojishi(creatTime) {
var djs = setInterval(function () {
var t = 59 - parseInt(((new Date() / 1000) - creatTime) / 60);//剩余分钟数
var s = 60 - parseInt(((new Date() / 1000) - creatTime) % 60); //剩余秒数
if (s == 60) {
s = 0;
t= t + 1
}
if (t <= 0 && s<=0) {
console.log(s)
clearInterval(djs);
console.log('订单超时,自动关闭')
$(".time").text('00');
$(".second").text('00');
return false;
}
$(".time").text(t>=10?t:"0"+t);
$(".second").text(s>=10?s:"0"+s);
}, 1000);
}
</script>
</body>
</html>
订单超过一小时自动关闭 倒数计
最新推荐文章于 2023-11-30 10:43:50 发布