后台返回了 一个创建时间需要根据这个时间 倒计时30分钟
const set = Date.parse(new Date('2021-08-04 11:10:00').toString()) //创建时间 获得时间戳
const end = set + 1000 * 60 * 30 //结束 在当前时间戳的基础上添加30分钟
const now = Date.parse(new Date().toString()) //当前时间
var maxtime = (end - now) /1000 //获得剩余时间 秒
CountDowns () {
if (maxtime >= 0) {
this.min = Math.floor(maxtime / 60);
if(this.min<9){
this.min = '0' + this.min
}
this.sec = Math.floor(maxtime % 60);
if(this.sec<9){
this.sec = '0' + this.sec
}
this.displays = ` ${this.min} 分 ${this.sec}秒`
maxtime--
} else{
clearInterval(this.displays );
// alert("时间到,结束!");
}
}
然后时间就会倒计时了
网友评论