<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > |
<html xmlns= "http://www.w3.org/1999/xhtml" > |
<head> |
|
<title>倒计时</title> |
</head> |
<body> |
<DIV id= "timer1" title= "11" > |
</DIV> |
<DIV id= "timer2" title= "11" > |
</DIV> |
<DIV id= "timer3" title= "11" > |
</DIV> |
|
<script language= "javascript" type= "text/javascript" > |
var thistime = new Date(); |
thistime=thistime.getTime(); |
setInterval( "my('2016-8-8 22:23:42','2016-8-8 22:23:52','timer1')" ,1000); |
setInterval( "my('2016-8-8 22:23:32','2016-8-8 22:23:52','timer2')" ,1000); |
setInterval( "my('2016-8-8 22:23:22','2016-8-8 22:23:52','timer3')" ,1000); |
function my(mstart,mend,mid){ |
var str=document.getElementById(mid); |
mstart=mstart.replace(/-/ig, "/" ); //处理IE兼容性 |
var start = new Date(mstart); |
start=start.getTime(); |
mend=mend.replace(/-/ig, "/" ); |
var end = new Date(mend); |
end=end.getTime(); |
var now = new Date(); |
now=now.getTime(); |
var allsecond=now - end; |
//document.getElementById("timers").innerHTML="倒计时还有:"+day+"天"+hour+"小时"+minute+"分"+second+"秒" ; |
|
var endsecond=now - end; |
endsecond=Math.floor(endsecond/1000); |
var startsecond=thistime - start; |
startsecond=Math.floor(startsecond/1000); |
var daojishi=startsecond -endsecond; |
//str.innerHTML="距离开始时间还有:"+startsecond+"秒;距离结束时间还有:"+endsecond+"秒;倒计时还有:"+daojishi+"秒" ; |
|
var day=Math.floor(daojishi/(60*60*24)); |
var hour=Math.floor((daojishi-day*24*60*60)/3600); |
var minute=Math.floor((daojishi-day*24*60*60-hour*3600)/60); |
var second=Math.floor(daojishi-day*24*60*60-hour*3600-minute*60); |
str.innerHTML= "</br>倒计时还有:" +day+ "天" +hour+ "小时" +minute+ "分" +second+ "秒" ; |
if (daojishi<0){ |
str.innerHTML= "倒计时结束" ; |
} |
} |
|
</script> |
|
|
</body> |
</html> |