倒计时
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div class="time"></div> <script src="jquery-1.11.3.min.js"></script> <script> //倒计时 window.setInterval(function(){ var startTime=new Date("2016/7/21 16:32:10"); /* var endTime=new Date("2016/6/20 12:32:10");*/ var endTime=new Date(); var startSeconds=startTime.getTime(); var endSeconds=endTime.getTime(); var spanTime=startSeconds-endSeconds; var time=document.getElementsByClassName("time")[0]; if(spanTime>0){ var day=Math.floor(spanTime/(1000*60*60*24)); var hours=Math.floor(spanTime/(1000*60*60))%24; var minutes=Math.floor(spanTime/(1000*60))%60; var seconds=Math.floor(spanTime/1000)%60; time.innerHTML="距离活动还剩:"+zero(day)+"天"+zero(hours)+"小时"+zero(minutes)+"分"+zero(seconds)+"秒"; }else{ time.innerHTML="活动已结束!"; } },1000); function zero(num){ return num<10?"0"+num:num; } </script> </body> </html>