function to2(t)
    
{
        
return t < 10 ? "0" + t : t;  
    }

    function showTime()
    
{
        mDate 
= new Date();
        var dayname 
= "日一二三四五六";
        var weekname,h,m,s;
        var yyyy 
= mDate.getFullYear() + "" + (mDate.getMonth() + 1+ "" + mDate.getDate() + "日   ";
       
        weekname 
= "星期" + dayname.charAt(mDate.getDay());
        
if(mDate.getDay() == 0)
        
{
            weekname 
= weekname.fontcolor("red");
        }

        
else if(mDate.getDay() == 6)
        
{
            weekname 
= weekname.fontcolor("green");
        }

        
else 
        

            weekname 
= weekname.fontcolor("blue");
        }

        
        h 
= mDate.getHours();//小时
        m = mDate.getMinutes();//
        s = mDate.getSeconds();//
   
        document.getElementById(
"spanTime").innerHTML = yyyy + weekname + " " + to2(h) + ":" + to2(m) + ":" + to2(s);//div也含有innerHTML属性
}


<body onload="setInterval('showTime()',1000)">//必须
   <span id=”spanTime”></span>
</body>