<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>当前时间显示 </title> </head> <body onload="startTime()"> <div id="time"></div> <h2 id="lasttime"></h2> <h2 id="lasttime1"></h2> </body> <script type="text/javascript"> function startTime() { var today=new Date() var endtime = new Date(‘12 10,15 22:00:00‘).getTime(); var nowtime = new Date().getTime(); var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() var myyear=today.getFullYear(); var mymonth=today.getMonth(); var monthArray=["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"] var mynowdate=today.getDate(); var myday=today.getDay(); var dayArray=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"] var lasttime=endtime-nowtime; var Tint=1000*60*60*24; var Hint=1000*60*60; var Mint=1000*60; var nowT=parseInt(lasttime/(1000*60*60*24)); var nowH=parseInt((lasttime-(Tint*nowT))/(1000*60*60)); var nowMin=parseInt((lasttime-(Tint*nowT)-(Hint*nowH))/(1000*60)); var nowS=parseInt((lasttime-(Tint*nowT)-(Hint*nowH)-(Mint*nowMin))/1000); m=checkTime(m) s=checkTime(s) document.getElementById(‘time‘).innerHTML=myyear+"年"+monthArray[mymonth]+mynowdate+"日"+dayArray[myday]+h+":"+m+":"+s; document.getElementById(‘lasttime‘).innerHTML=nowT+"天"+nowH+"小时"+nowMin+"分钟"+nowS+"秒"; setTimeout(‘startTime()‘,1000); } function checkTime(i) { if (i<10) {i="0" + i} return i } </script> </html>
时间: 2024-12-28 08:34:47