javascript倒计时。首先我们要设置倒计时时间格式,方法如下:
function currTimeForm(currTime){
var day = Math.floor(currTime/60/60/24);
var hour = Math.floor(currTime/60/60%24);
var min = Math.floor(currTime/60%60);
var sec = Math.floor(currTime%60);
if(day<10){
day = "0"+day;
}
if(hour<10){
hour = "0"+hour;
}
if(min<10){
min = "0"+min;
}
if(sec<10){
sec = "0"+sec;
}
return day+":"+hour+":"+min+":"+sec;
}
这个倒计时时间格式:00:00:00:00。
倒计时方法:
function DateFormate(time){
var dateObj = parseInt(time);
var intervel = setInterval(function(){
var currTime = dateObj-parseInt(new Date().getTime()/1000);
if(currTime == 0){
clearInterval(intervel);
window.location.reload();
}else if(currTime>0){
document.getElementById("daojiTime").innerHTML = currTimeForm(currTime);
}else{
clearInterval(intervel);
alert("结束了!");
}
},1000);
}