js倒计时
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js倒计时</title> <style> .div { height:500px; width:300px; margin:20% auto;} h3,h2 { text-align:center;} </style> </head> <body bgcolor="#FF0000"> <div class="div"> <h3>距元旦还有</h3> <h2 id="time"></h2> </div> <script> function tt(){ var end = "2018-01-01 00:00:00" var endDate = new Date(end).getTime(); //alert(endDate); var star = new Date(); var starDate = star.getTime(); var temp = endDate-starDate; var day = Math.floor(temp/(1000*60*60*24)); var hh = Math.floor((temp-day*24*60*60*1000)/(1000*60*60)); var mm = Math.floor((temp-day*24*60*60*1000-hh*3600000)/(1000*60)); var ss = Math.floor((temp-day*24*60*60*1000-hh*3600000-mm*60000)/1000); //alert(day+"--"+hh+"--"+mm+"--"+ss); document.getElementById("time").innerHTML = day+"天"+hh+"小时"+mm+"分钟"+ss+"秒"; } tt(); window.setInterval(tt,1000); </script> </body> </html>