<div class="codetitle"> <span><a style="CURSOR: pointer" data="1827" class="copybut" id="copybut1827" onclick="doCopy('code1827')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code1827"> <br> <br> <br><title> JavaScript實作頁面即時顯示目前時間</title> <br> <br> <br><script language="javascript"> <BR>function showtime() <BR>{ <BR>var today,hour,second,minute,year,month,date; <BR>var strDate ; <BR>today=new Date(); <BR>var n_day = today.getDay(); <BR>switch (n_day) <BR>{ <BR>case 0:{ <BR>strDate = "星期日" <BR>}break; <BR>case 1:{ <BR>strDate = "星期一" <BR>}break; <BR>caseasecase>case 2:{ <BR>strDate ="星期二" <BR>}break; <BR>case 3:{ <BR>strDate = "星期三" <BR>}break; <BR>case 4:{ <BR>strDate = "星期四" <BR>}break; <BR>case 5:{ <BR>strDate = "星期五" <BR>}break; <BR>case 6:{ <BR>strDate = "星期六" <BR>}break ; <BR>case 7:{ <BR>strDate = "星期日" <BR>}break; <BR>} <BR>year = today.getYear(); <BR>month = today.getMonth() 1; <BR>date = today.getDate(); <BR>hour = today.getHours(); <BR>minute =today.getMinutes(); <BR>second = today.getSeconds(); <BR>if(month< 10) month="0" month; <BR>if(date<10) date="0" date; <BR>if(hour<10) hour="0" hour; <BR>if(minute<10) minute="0" minute; <BR>if(second<10) second="0" second; <BR>document.getElementById('time').innerHTML = year "年" month "月" date "日" strDate " " hour ":" minute ":" second; //顯示時間<BR>setTimeout("showtime();", 1000); //設定函數自動執行時間為1000 ms(1 s) <BR>} <BR></script><br><div id="time"></div> <br><script language="javascript"> showtime();</script><br> <br><br> </div>