vue项目实现的拍卖状态的判断以及倒计时显示
获取当前时间
判断开始时间是否大于当前时间(true未开始)
判断结束时间是否大于当前时间且开始时间小于当前时间(true进行中)
否则(已结束)
getTime:function(begin,end){
let date=new Date();
let y=date.getFullYear();
let m=date.getMonth()+1;
let d=date.getDate();
let h=this.toTime(date.getHours());
let n=this.toTime(date.getMinutes());
let s=this.toTime(date.getSeconds());
let t2=y+'-'+m+'-'+d+' '+h+':'+n+':'+s;
let d2=t2.replace(/\-/g,"/");
let d1=new Date(d2);
let t;
let status;
if(begin-d1>0){
t=begin;
status="距离开始:"
}else if(end-d1>0&&begin-d1<0){
t=end;
status="距离结束:"
}else{
status="已结束"
t=d1=0;
}
let day=parseInt((parseInt(t - d1) / 1000 / 60) /60 / 24);
let hours=(parseInt(t - d1) / 1000 / 60) /60 - day*24;
let minutes=(parseInt(t-d1)/1000 / 60) - day*24*60-parseInt(hours)*60;
let seconds=(parseInt(t - d1) / 1000)-day*24*60*60-parseInt(hours)*60*60-parseInt(minutes)*60;
//console.log(parseInt(begin - d1)/1000);//两个时间相差的毫秒数
//console.log(parseInt(t - d1) / 1000);//两个时间相差的秒数
//console.log(parseInt(t - d1) / 1000 / 60);//两个时间相差的分钟数
//console.log(parseInt(t - d1) / 1000 / 60 /60);//两个时间相差的小时数
// console.log(day+"天"+parseInt(me)+"小时");
return status+day+"天"+parseInt(hours)+":"+this.toTime(parseInt(minutes))+":"+this.toTime(parseInt(seconds));
},
toTime:function(n){
return n>9?n:'0'+n;
}
fnCountDown:function(){
var t1=this.auctionDetail.begintime;
var d1 = t1.replace(/\-/g, "/");
var beginTime = new Date(d1);
var t2=this.auctionDetail.endtime;
var d2 = t1.replace(/\-/g, "/");
var endTime = new Date(d2);
this.countDown=this.getTime(beginTime,endTime);
clearInterval(this.timer);
this.timer=setInterval(()=>{
this.countDown=this.getTime(beginTime,endTime);
},1000)
},
网友评论