Js代码 复制代码 代码如下: //-----------------------------方式一--------------------------------------------- <BR>function startTime(){ <BR>var today=new Date(); <BR>var strDate=(" "+today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"); <BR>var n_day=today.getDay(); <BR>switch(n_day){ <BR>case 0: <BR>{strDate=strDate+" 星期日 "}break; <BR>case 1: <BR>{strDate=strDate+" 星期一 "}break; <BR>case 2: <BR>{strDate=strDate+" 星期二 "}break; <BR>case 3: <BR>{strDate=strDate+" 星期三 "}break; <BR>case 4: <BR>{strDate=strDate+" 星期四 "}break; <BR>case 5: <BR>{strDate=strDate+" 星期五 "}break; <BR>case 6: <BR>{strDate=strDate+" 星期六 "}break; <BR>case 7: <BR>{strDate=strDate+" 星期日 "}break; <BR>} <BR>//增加时分秒 <BR>// add a zero in front of numbers<10 <BR>var h=today.getHours(); <BR>var m=today.getMinutes(); <BR>var s=today.getSeconds() <BR>m=checkTime(m); <BR>s=checkTime(s); <BR>strDate=strDate+" "+h+":"+m+":"+s; <BR>document.getElementById('txt').innerHTML=strDate; <BR>t=setTimeout('startTime()',500) <BR>} <br><br>function checkTime(i){ <BR>if (i<10) {i="0" + i} <BR>return i <BR>} <BR> //--------------------------------方式二----------------------------------------- <BR>var today=new Date(); <BR>var strDate=(" "+today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"); <BR>var n_day=today.getDay(); <BR>switch(n_day){ <BR>case 0: <BR>{strDate=strDate+" 星期日 "}break; <BR>case 1: <BR>{strDate=strDate+" 星期一 "}break; <BR>case 2: <BR>{strDate=strDate+" 星期二 "}break; <BR>case 3: <BR>{strDate=strDate+" 星期三 "}break; <BR>case 4: <BR>{strDate=strDate+" 星期四 "}break; <BR>case 5: <BR>{strDate=strDate+" 星期五 "}break; <BR>case 6: <BR>{strDate=strDate+" 星期六 "}break; <BR>case 7: <BR>{strDate=strDate+" 星期日 "}break; <BR>} <BR>document.write(strDate); <BR>