Dreamweaver中如何实现实时显示系统时间?

解决方案 »

  1.   

    这个网上很多的,我帮你找一个吧
    <script type="text/javascript">
    function showLocale(objD)
    {
    var str,colorhead,colorfoot;
    var yy = objD.getYear();
    if(yy<1900) yy = yy+1900;
    var MM = objD.getMonth()+1;
    if(MM<10) MM = '0' + MM;
    var dd = objD.getDate();
    if(dd<10) dd = '0' + dd;
    var hh = objD.getHours();
    if(hh<10) hh = '0' + hh;
    var mm = objD.getMinutes();
    if(mm<10) mm = '0' + mm;
    var ss = objD.getSeconds();
    if(ss<10) ss = '0' + ss;
    var ww = objD.getDay();
    if ( ww==0 ) colorhead="<font color=\"#FF0000\">";
    if ( ww > 0 && ww < 6 ) colorhead="<font color=\"#373737\">";
    if ( ww==6 ) colorhead="<font color=\"#008000\">";
    if (ww==0) ww="星期日";
    if (ww==1) ww="星期一";
    if (ww==2) ww="星期二";
    if (ww==3) ww="星期三";
    if (ww==4) ww="星期四";
    if (ww==5) ww="星期五";
    if (ww==6) ww="星期六";
    colorfoot="</font>"
    str = colorhead + yy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss + " " + ww + colorfoot;
    return(str);
    }
    function tick()
    {
    var today;
    today = new Date();
    document.getElementById("localtime").innerHTML = showLocale(today);
    window.setTimeout("tick()", 1000);
    }
    tick();
    </script>
      

  2.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>年月日时分秒的即时显示-ACCP教程网</title>
    </head>
    <body onload=startclock()>
    <form name="clock">
    <script language="JavaScript">
    var timerID = null;
    var timerRunning = false;
    function stopclock (){
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false;}
    function startclock () {
    stopclock();
    showtime();}
    function showtime () {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds()
    var timeValue = now.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日" +((hours >= 12) ? " 下午 " : " 上午 " )
    timeValue += ((hours >12) ? hours -12 :hours)
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds
    document.clock.thetime.value = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;}
    </script>
    <input name="thetime" style="font-size: 9pt;color:#000000;border:1px solid #FFFFFF; ; " size="28"></form>
    </body>
    这个可以实现效果的,你运行一下就OK了
      

  3.   

    我新建的js内容为3楼的,以showLocale(objD)存盘,用记事本写html内容为4楼的,以showtime.html存盘,怎么运行什么都没有???
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>年月日时分秒的即时显示-ACCP教程网</title>
    </head>
    <body onload=startclock()>
    <form name="clock">
    <script language="JavaScript">
    var timerID = null;
    var timerRunning = false;
    function stopclock (){
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false;}
    function startclock () {
    stopclock();
    showtime();}
    function showtime () {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds()
    var timeValue = now.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日" +((hours >= 12) ? " 下午 " : " 上午 " )
    timeValue += ((hours >12) ? hours -12 :hours)
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds
    document.clock.thetime.value = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;}
    </script>
    <input name="thetime" style="font-size: 9pt;color:#000000;border:1px solid #FFFFFF; ; " size="28"></form>
    </body>
    这个直接保存showtime.html就可以显示时间啊
    不好意思,这几天忙,没有打开论坛看哈