https://www.jianshu.com/p/df43f1983eab
// 秒杀倒计时
_cutDown(t) {
let _self = this
let startTime = t.startTime // 开始时间时间戳
let endTime = t.endTime // 结束时间时间戳
// 当前日期转换为1970-01-01后的时间戳
let nowTime = format.time((new Date()).getTime(), 'YYYY-MM-DD HH:mm:ss')
nowTime = new Date(nowTime.replace(/.{10}/, '1970-01-01')).getTime()
let times = (endTime - nowTime) / 1000
let timmer = setInterval(() => {
if (times <= 0) {
_self.setData({ finish: true })
clearInterval(timmer)
timmer = null
}
times--
let HH = Math.floor(times / 3600)
let mm = Math.floor((times - HH * 3600) / 60)
let ss = Math.floor((times - HH * 3600) % 60)
_self.setData({
HH: format.twoDigit(HH),
mm: format.twoDigit(mm),
ss: format.twoDigit(ss)
})
}, 1000)
},
网友评论