Fork me on GitHub

js倒计时

// 初始化加载
$(function () {
setInterval("leftTimer()", 1000);

});
// 倒计时计时器
function leftTimer() {

var leftTime = (new Date(year, month, day, hour, minute, second)) - (new Date()); //计算剩余的毫秒数
var days = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数
var hours = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时
var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
var strDays = checkTime(days);
var strHours = checkTime(hours);
var strMinutes = checkTime(minutes);
var strSeconds = checkTime(seconds);
if (leftTime <= 0) {
clearInterval("leftTimer");
document.getElementById("timer").innerHTML = "0天0时0分0秒";
} else {
//setInterval("leftTimer(" + year + "," + month + "," + day + "," + hour + "," + minute + "," + second + ")", 1000);
document.getElementById("timer").innerHTML = strDays + "天" + strHours + "时" + strMinutes + "分" + strSeconds + "秒";
}
}

posted @ 2021-07-16 16:37  WantRemake  阅读(46)  评论(0编辑  收藏  举报