js实现倒计时
function daojishi() {
// 获取当前时间
var myDate = new Date();
myDate.getDate();
//获取时分秒
var h = myDate.getHours();
var m = myDate.getMinutes();
var s = myDate.getSeconds();
// 计算获取倒计时
var hh = h*3600+m*60+s
var hhh = 86400-hh;
// 获取倒计时的小时
var newh= parseInt(hhh/3600)
// 获取倒计时的分钟
var newm = parseInt((hhh%3600)/60)
// 获取倒计时的秒
var news = (hhh%3600)%60
// 判断小于10前面加0,好看
if (newh<10) {
newh = '0'+newh
}
if (newm<10) {
newm = '0'+newm
}
if (news<10) {
news = '0'+news
}
// 将处理好的时间放到页面上
elh.text(newh)
elm.text(newm)
els.text(news)
}
// 执行倒计时
setInterval(daojishi, 1000)