js 小程序倒计时

 
let endtime = that.data.endtime;
setInterval(function () {
let nowtime = Date.parse(new Date()) / 1000;
if ((endtime - nowtime) >= 0) {
let timer = endtime - nowtime;
let d = parseInt(timer / 60 / 60 / 60 / 24, 10);//计算剩余小时
let h = parseInt(timer / 60 / 60 % 24, 10);//计算剩余小时
let m = parseInt(timer / 60 % 60, 10);//计算剩余分钟
let s = parseInt(timer % 60, 10);//计算剩余秒数
h = h < 10 ? h : h;
m = m < 10 ? m : m;
s = s < 10 ? s : s;
that.setData({
days: d,
hours: h,
minutes: m,
seconds: s,
})
} else {
that.setData({
 
})
}
}, 1000)
posted @ 2018-01-24 10:21  zc_boy  阅读(537)  评论(0编辑  收藏  举报