$('span').siblings('.gtime').each(function () {
var strtime = $(this).attr('data-time');
var date = new Date(strtime);
time1 = date.getTime()+{$chaoshi}*1000;
console.log(new Date().getTime());
xtime=getRandomCode(time1,$(this))
})
function getRandomCode(xtime,obj) {
if ((xtime-(new Date()).getTime()) <= 0) {
var url="{:url('goods/fenghao1')}";
var buyid =obj.parent().attr('id');
// alert(buyid);
$.ajax({
type: "post",
url: url,
data: {id:buyid},
dataType: "json",
success: function (data) {
console.log('封号了');
}
})
obj.text('超时了');
} else {
xtime-=1000;
ytime=parseInt((xtime-(new Date()).getTime())/60000)
obj.text(ytime+'分钟');
}
setTimeout(function () {
getRandomCode(xtime,obj);
}, 1000);
}
function timestampToTime(timestamp) {
var date = new Date(timestamp );//时间戳为10位需*1000,时间戳为13位的话不需乘1000
// var Y = date.getFullYear() + '-';
// var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
// var D = date.getDate() + ' ';
var h = date.getHours() + ':';
var m = date.getMinutes() + ':';
var s = date.getSeconds();
return h+m+s;
}
网友评论