最新知识
热点文章
广州网站设计公司 >> 程序知识 >> 实时走动的JS时间代码
  • 实时走动的JS时间代码
  • 来源:广州网站建设 作者:Helly 日期:2009-3-3 14:46:01 点击:
  • 在很多网站上会用到一个实时的JS时间,在这里广州网站建设为大家分享一个实时走动的JS时间代码:

    代码如下:

    以下是引用片段:
    <script>
    function tick() {
    var hours, minutes, seconds, xfile;
    var intHours, intMinutes, intSeconds;
    var today;
    today = new Date();
    intHours = today.getHours();
    intMinutes = today.getMinutes();
    intSeconds = today.getSeconds();
    if (intHours == 0) {
    hours = "12:";
    xfile = "午夜";
    } else if (intHours < 12) {
    hours = intHours+":";
    xfile = "上午";
    } else if (intHours == 12) {
    hours = "12:";
    xfile = "正午";
    } else {
    intHours = intHours - 12
    hours = intHours + ":";
    xfile = "下午";
    }
    if (intMinutes < 10) {
    minutes = "0"+intMinutes+":";
    } else {
    minutes = intMinutes+":";
    }
    if (intSeconds < 10) {
    seconds = "0"+intSeconds+" ";
    } else {
    seconds = intSeconds+" ";
    }
    timeString = xfile+hours+minutes+seconds;
    Clock.innerHTML = timeString;
    window.setTimeout("tick();", 100);
    }
    window.onload = tick;
    </script>

    把上面的代码保存为一个JS文件,然后进行下面的调用就可以。

    以下是引用片段:
    <div id="Clock" align="center" style="font-size: 20; color:#000000"></div>

  • 文章来源:广州网站建设
  • 上一篇:网站如何在本地进行浏览
©2008 广州网站制作 Corporation 版权所有