1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body onload="get()"> 8 <div id="CountMsg" class="HotDate"> 9 <span id="t_d">00天</span> 10 <span id="t_h">00时</span> 11 <span id="t_m">00分</span> 12 <span id="t_s">00秒</span> 13 </div> 14 <script type="text/javascript"> 15 function get(){ 16 var end= new Date('2018/05/1 10:00:00'); 17 var now = new Date(); 18 var t =end.getTime() - now.getTime(); //getTime()返回距...之间的毫秒数。 19 var d=Math.floor(t/1000/60/60/24); 20 var h=Math.floor(t/1000/60/60%24); 21 var m=Math.floor(t/1000/60%60); 22 var s=Math.floor(t/1000%60); 23 24 document.getElementById("t_d").innerHTML = d + "天"; 25 document.getElementById("t_h").innerHTML = h + "时"; 26 document.getElementById("t_m").innerHTML = m + "分"; 27 document.getElementById("t_s").innerHTML = s + "秒"; 28 } 29 setInterval(get,1000); 30 </script> 31 </body> 32 </html>