1、html <!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>输出日期时间</title> </head> <body> <h1>当前日期时间</h1> <div id="content"></div> <script src="Date.js"></script> </body> </html> 2、js // JavaScript Document var t=null; t=setTimeout(beg,1000) function beg(){ clearTimeout(t); var now=new Date(); var year=now.getFullYear(); var month=now.getMonth()+1; var date=now.getDate(); var array=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六 "); var i=now.getDay(); var hour=now.getHours(); if (hour<10) { hour="0"+hour; } var minute=now.getMinutes(); if (minute<10) { minute="0"+minute; } var second=now.getSeconds(); if (second<10) { second="0"+second; } var msg=‘<h2>日期时间</h2><p>‘+hour+‘:‘+minute+‘:‘+second+‘<br>‘+year+‘/‘+month+‘/‘+date+‘ ‘+array[i]+‘</p>‘; var el1=document.getElementById("content"); el1.innerHTML=msg; t=setTimeout(beg,1000); }
时间: 2024-10-06 11:36:03