html52.com
我爱小程序-开发者交流社区

定时器

if (wx.getStorageSync('timeLength')) {

console.log('已输入生产日期')

that.setData({

timeLength: wx.getStorageSync('timeLength')

})


var time = that.data.timeLength

var timer = setInterval(function () {

time--

var day = (Math.floor(time / 60 / 60 / 24) > 0) ? Math.floor(time / 60 / 60 / 24) : 0

var hour = Math.floor((time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24) / 60 / 60)

var minute = Math.floor((time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24 - Math.floor((time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24) / 60 / 60) * 60 * 60) / 60)

var second = Math.floor(time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24 - Math.floor((time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24) / 60 / 60) * 60 * 60 - Math.floor((time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24 - Math.floor((time - Math.floor(time / 60 / 60 / 24) * 60 * 60 * 24) / 60 / 60) * 60 * 60) / 60) * 60)


if (that.data.dayNum <= 0) {

that.setData({

dayNum: 0

})

}

if (that.data.hourNum <= 0) {

that.setData({

hourNum: 0

})

}

if (that.data.minuteNum <= 0) {

that.setData({

minuteNum: 0

})

}

if (that.data.secondNum <= 0) {

that.setData({

secondNum: 0

})

}

day = day > 9 ? day : '0' + day

hour = hour > 9 ? hour : '0' + hour

minute = minute > 9 ? minute : '0' + minute

second = second > 9 ? second : '0' + second

wx.setStorageSync('timeLength', time)

that.setData({

timeLength: wx.getStorageSync('timeLength'),

dayNum: day,

hourNum: hour,

minuteNum: minute,

secondNum: second

})

}, 1000)

}


刚进入页面时时间减少不正常(+2秒-1秒) 跑一段时间后又正常了

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付