1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>js-倒计时</title> 6 </head> 7 8 <body> 9 10 <div id="box"></div> 11 12 <script language="javascript"> 13 14 var timer2=new Date("5/01/2015 00:00:00"); 15 var tim_box=document.getElementById("box"); 16 var yer,days,hors,miu,sec; 17 function js(){ 18 var timer=new Date(); 19 yer=Math.floor((timer2-timer)/(365*24*60*60*1000)); 20 days=Math.floor((timer2-timer)/(24*60*60*1000)-(yer*365)); 21 hors=Math.floor((timer2-timer)/(1000*60*60)-(days*24)-(yer*365*24)); 22 miu=Math.floor((timer2-timer)/(60*1000)-(days*24*60)-(yer*365*24*60)-(hors*60)); 23 sec=Math.floor((timer2-timer)/1000-(days*24*60*60)-(yer*365*24*60*60)-(hors*60*60)-(miu*60)); 24 tim_box.innerHTML="距离2015年5月1日还有"+yer+"年"+days+"天"+hors+"小时"+miu+"分钟"+sec+"秒"; 25 setTimeout("js()",1000); 26 } 27 js(); 28 </script> 29 30 </body> 31 </html>