setInterval("webjx.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());", 1000);
</script>
方法二:
<script type="text/javascript">
//以下是年月日星期显示
tmpDate = new Date(); date = tmpDate.getDate(); month = tmpDate.getMonth() + 1; year = tmpDate.getYear(); document.write(year); document.write("."); document.write(month); document.write("."); document.write(date); document.write(" "); myArray = new Array(6);
myArray[0] = "星期日 "
myArray[1] = "星期一 "
myArray[2] = "星期二 "
myArray[3] = "星期三 "
myArray[4] = "星期四 "
myArray[5] = "星期五 "
myArray[6] = "星期六 "
weekday = tmpDate.getDay(); if (weekday == 0 | weekday == 6) {
document.write(myArray[weekday])
} else {
document.write(myArray[weekday])
};
//以下是时间显示
var tags_before_clock = ""
var tags_after_clock = ""
if(navigator.appName == "Netscape") {
document.write('<layer id="clock"></layer>');
}
if (navigator.appVersion.indexOf("MSIE") != -1){
document.write('<span id="clock"></span>');
}
function showclock()
{
var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var col = ":";
var spc = " ";
var apm;
if ( hour >24 )
{
apm="P.M.";
hour=hour-24;
}
else
{
apm="A.M.";
}
if (hour == 0) hour=24;
if (min<=9) min="0"+min;
if (sec<=9) sec="0"+sec;
if(navigator.appName == "Netscape")
{
document.clock.document.write(tags_before_clock
+hour+col+min+col+sec+spc+tags_after_clock);
document.clock.document.close();
}
if (navigator.appVersion.indexOf("MSIE") != -1)
{
clock.innerHTML = tags_before_clock+hour+col+min+col+sec;
}
}
setInterval("showclock()",1000);
</script>