var
interval
=
1000
function
ShowCountDown(year,month,day,divname)
{
var
now
=
new
Date()
var
endDate
=
new
Date(year,
month-1,
day)
var
leftTime=endDate.getTime()-now.getTime()
var
leftsecond
=
parseInt(leftTime/1000)
//var
day1=parseInt(leftsecond/(24*60*60*6))
var
day1=Math.floor(leftsecond/(60*60*24))
var
hour=Math.floor((leftsecond-day1*24*60*60)/3600)
var
minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60)
var
second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60)
var
cc
=
document.getElementById(divname)
cc.innerHTML
=
"脚本之家提示距离"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒"
}
window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1')},
interval)
[Ctrl+A
全选
注:如需引入外部Js需刷新才能执行]
你需要的只是一个倒计时函数,方法有很多,例如:
倒计时函数:
/*** daysID : 显示天数容器id
* hoursID : 显示小时容器id
* minuteID : 显示分钟容器id
* secondID : 显示秒数容器id
* endTime :结束时间,设置倒计时的时间
* **/
function getRTime(daysID,hoursID,minuteID,secondID,endTime){
var EndTime = new Date(endTime)
var NowTime = new Date()
var t = EndTime.getTime() - NowTime.getTime()
var d = Math.floor(t/1000/60/60/24)
var h = Math.floor(t/1000/60/60%24)
var m = Math.floor(t/1000/60%60)
var s = Math.floor(t/1000%60)
if(s < 0){
clearInterval(timer)
d = 0
h = 0
m = 0
s = 0
}
document.getElementById(daysID).innerHTML = d
document.getElementById(hoursID).innerHTML = h
document.getElementById(minuteID).innerHTML = m
document.getElementById(secondID).innerHTML = s
}
调用:
var timer = setInterval(getRTime('days','hours','minute',null,'2017/6/22 24:00:00'),1000)