天时分秒毫秒倒计时
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>时间倒计时</title> <style> div{ margin: 100px auto; font:bold 60px "仿宋"; } </style> </head> <body> <script> function t( n ) { if( n > 9 ){ return n; }else{ return "0"+n; } } function timer ( year, month, day, divId) { var nowDate = new Date(); var endDate = new Date( year, month-1, day ); var cerDate = endDate.getTime() - nowDate.getTime(); var cerTime = parseInt(cerDate / 1000); var dd = Math.floor( cerTime /(60*60*24)); var hour = Math.floor( (cerTime - dd *60*60*24)/3600); var minute = Math.floor( (cerTime - dd *60*60*24 - hour * 60*60)/60); var second = Math.floor( (cerTime - dd *60*60*24 - hour * 60*60 - minute *60) ); var ms = Math.floor(parseInt(cerDate / 10)%60); var oDiv = document.getElementById( divId ); oDiv.innerHTML = "距离规定时间"+ t( year )+ "年"+ t(month)+"月"+ t(day)+"日还有:"+ t(dd)+"天"+t(hour) +"时"+t(minute)+"分"+t(second)+":"+ t(ms); } window.setInterval(function(){ timer( 2017, 12, 16, "txt") },10) </script> <div id="txt"></div> </body> </html>
用我拥有,换你没有,竭尽所有