格式为:天、小时、分、秒
data{
timer: 86400,// 模拟时间(秒)
},
// 24小时倒计时 加载页面时时间戳由从服务器获取
timefilter(time) {
return time = (time / 10) < 1 ? "0" + time : time
},
timestampToTime() {
let s = this.data.timer - 1
if (timers) clearInterval(timers);
let timers = setInterval(()=>{
let days = this.timefilter(Math.floor(s / 86400));
let hour = this.timefilter(Math.floor(s / 3600) % 24);
let min = this.timefilter(Math.floor(s / 60) % 60);
let sec = this.timefilter(s % 60);
this.setData({
days,
hour,
min,
sec
})
s = s -1;
if(s <= 0) {
clearInterval(timers)
}
},1000)
this.setData({
timers
})
},