<input id="showtime"  
readonly="readonly"/>  
<script type="text/
javascript">  
    function getnowtime() {  
        var now = new date();  
        document.getelementbyid("showtime").value = now.getfullyear() + "-"  
                + (now.getmonth() + 1) + "-" + now.getdate();  
        document.getelementbyid("showtime").value += " " + now.gethours() + ":"  
                + now.getminutes() + ":" + now.getseconds();  
    }  
    window.setinterval("getnowtime()", 1000);  
</script> 
function showtime() //显示时间的方法  
{  
document.getelementbyid('time').innerhtml=new date().tolocalestring()+' 星期'+'日一二三四五六'.charat(new date().getday());//显示
服务器时间  
}  
setinterval("showtime()", "1000");  (
脚本学堂 www.jb200.com 编辑整理)
 
<html xmlns="http://www.w3.org/1999/xhtml" >  
<head>  
<title>js动态显示时间</title>  
</head>  
<body>  
当前时间:<div  id="time"></div>  
<script>  
var xmlhttp = new activexobject("microsoft.xmlhttp");//创建xmlhttp对象  
xmlhttp.open("head","http://www.beijing-time.org",false);  //从哪个服务器上获取时间  
xmlhttp.send();  //连接服务器  
var offset = date.parse(xmlhttp.getresponseheader("date"));//获取标头中的时间  
offset -= (new date).gettime(); //获取本地时间与服务器时间的间隔  
function showtime() //显示时间的方法  
{  
 var d = new date;  //获取当前时间                                      
 d.settime(d.gettime()+offset); //通过服务器和本地的
时间间隔获取当前服务器时间  
 document.getelementbyid('time').innerhtml=d.tolocalestring();//显示服务器时间  
}  
setinterval("showtime()", "1000");  
</script>  
</body>  
</html>  
 
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">    
<head>    
<meta http-equiv="content-type" content="text/html; charset=gbk"/>    
<title>js显示动态时间_www.jb200.com</title>    
<script type="text/javascript">    
    get=function (id){return document.getelementbyid(id)}    
    if(document.all){    
        window.xmlhttprequest=function(){    
            var get=['microsoft.xmlhttp','msxml2.xmlhttp'];    
            for(var i=0;i<get.length;i++){try{return new activexobject(get[i])}catch(e){}};    
        };    
    }    
    webdate=function(fn){    
        var htime=new xmlhttprequest();    
        htime.onreadystatechange=function(){htime.readystate==4&&(fn(new date(htime.getresponseheader('date'))))};    
        htime.open('head', '/?_='+(-new date));    
        htime.send(null);    
    }    
    window.time=new date();    
    targettime=new date();    
    time2string=function (t){    
            with(t)return [getfullyear(),'年'    
                ,('0'+(getmonth()+1)).slice(-2),'月'    
                ,('0'+getdate()).slice(-2),'日 '    
                ,('0'+gethours()).slice(-2),': '    
                ,('0'+getminutes()).slice(-2),': '    
                ,('0'+getseconds()).slice(-2)].join('')    
    }    
    int2time=function (m){    
        m-=(d=parseint(m/86400000))*86400000;    
        m-=(h=parseint(m/3600000))*3600000;    
        s=parseint((m-=(m=parseint(m/60000))*60000)/1000);    
        return d+'天'+h+'小时'+m+'分'+s+'秒'    
    }    
    setinterval(function (){  (脚本学堂 www.jb200.com 编辑整理)  
        webdate(function (webtime){    
            get('web').innerhtml=time2string(time=webtime);    
        })    
        get('locale').innerhtml=time2string(new date);    
        get('time').innerhtml=int2time(targettime-time);    
        if ((targettime-time)<0) {    
            get('time').innerhtml = 'game over';    
        }    
    },1000)    
 </script>        
</head>    
<body>    
设定时间:2012年12月31日0时0分0秒<br>    
服务器时间:<span id='web'>loading...</span><br>    
本地时间:<span id="locale">loading...</span><br>    
倒计时时间:<span id="time">loading...</span>    
<script type="text/javascript" charset="utf-8">    
    targettime=new date(2012,12,31,00,00,00);    
</script>    
</body>    
</html>