你需要的只是一个倒计时函数,方法有很多,例如:
倒计时函数:
/*** 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)你好,两个时间戳比较简单,new两个当前date对象,将时、分,分别设置为零点和23:59分,再gettime就可以了。只接代码:
var zero = new date()
var eleven = new date()
zero.sethours(0)
zero.setminutes(0)
zero.setseconds(0)
eleven.sethours(23)
eleven.setminutes(59)
eleven.setseconds(0)
console.log('今天零点:' + zero.gettime())
console.log('23:59:' + eleven.gettime())希望解决了你的问题,如有疑问可追问!