未支付订单的30分钟倒计时
多个未支付的订单,倒计时30分钟,超过删除
timeTimer();//先走一下
//单纯分钟和秒倒计时
var timer = setInterval(jishiMs,1000);
function jishiMs() {
if($('.daojishi').length <= 0){
clearInterval(timer);
}else{
timeTimer();
}
}
function timeTimer() {
if($('.daojishi').length > 0) { //如果有未支付的订单(将未支付的订单给统一的类daojishi)
$('.daojishi').each(function (data, index) {
var orderTime = $(this).attr('otime');//下单时间(日期)
var nowTime = Date.parse(new Date());//当前时间(时间戳)
//var oid = $(this).attr('orderid');//订单id(PS:用于后续操作)
var time1 = datetime_to_unix(orderTime);//下单时间戳(如果保存的是时间戳直接计算)
var cha = nowTime / 1000 - time1;//差值
if (cha < 1800) {
var M = 29 - Math.floor(cha / 60);
var S = 59 - Math.floor(cha % 60);
if (M < 10) {
M = '0' + M;
}
if (S < 10) {
S = '0' + S;
}
$(this).text(M + ':' + S);
} else {
//倒计时结束,执行操作
}
})
}
}
//将日期转为时间戳
function datetime_to_unix(datetime){
var tmp_datetime = datetime.replace(/:/g,'-');
tmp_datetime = tmp_datetime.replace(/ /g,'-');
var arr = tmp_datetime.split("-");
var now = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
return parseInt(now.getTime()/1000);
}