1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 <script language="javascript"> 7 //日期,时间 8 function startTime() 9 { 10 var today=new Date(); 11 var yy=today.getFullYear();//年 12 var mm=today.getMonth();//月 13 var d=today.getDate();//一月中第几天 14 var day=today.getDay();//星期几 15 var h=today.getHours();//小时 16 var m=today.getMinutes();//分钟 17 var s=today.getSeconds();//秒 18 h=checkTime(h); 19 m=checkTime(m); 20 s=checkTime(s); 21 day=checkDay(day); 22 document.getElementById(‘date‘).innerHTML=yy+"年"+mm+"月"+d+"日"+" "+h+":"+m+":"+s+" "+day; 23 t=setTimeout(‘startTime()‘,500); 24 } 25 function checkTime(i) 26 { 27 if(i<10){i="0"+i;} 28 return i; 29 } 30 function checkDay(i) 31 { 32 switch(i) 33 { 34 case 0: 35 return "星期天"; 36 break; 37 case 1: 38 return "星期一"; 39 break; 40 case 2: 41 return "星期二"; 42 break; 43 case 3: 44 return "星期三"; 45 break; 46 case 4: 47 return "星期四"; 48 break; 49 case 5: 50 return "星期五"; 51 break; 52 case 6: 53 return "星期六"; 54 break; 55 default: 56 return "时间出错了!"; 57 break; 58 } 59 } 60 </script> 61 </head> 62 63 <body onLoad="startTime()"> 64 <div id="date"></div> 65 </body> 66 </html>
时间: 2024-10-18 07:52:16