当前位置: 代码迷 >> ASP.NET >> javascript中怎么在页面实现显示当前系统时间,并且要每时每刻都要刷新
  详细解决方案

javascript中怎么在页面实现显示当前系统时间,并且要每时每刻都要刷新

热度:2154   发布时间:2013-02-25 00:00:00.0
javascript中怎样在页面实现显示当前系统时间,并且要每时每刻都要刷新
如题:在客户端显示当前系统时间 如 :2011/11/6 14:55 并且要与系统时间同步的那种

------解决方案--------------------------------------------------------
HTML code
<!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"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>demo</title>    <script >        window.onload=function(){            showTime();        }        var showTime =function(){            var nowTime = new Date();            document.getElementById("msg").innerHTML = nowTime;                       setTimeout("getTime()",100);        }</script></head><body>  <div id="msg">sdf  </div></body></html>
------解决方案--------------------------------------------------------
setTimeout("getTime()",100);
=>
setTimeout("showTime()",100); 
写快了 。
------解决方案--------------------------------------------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html xmlns="http://www.w3.org/1999/xhtml"><head><script>function displayDateTime(XelementID) {    var myDate = new Date();    var year = myDate.getFullYear();    var month = myDate.getMonth() + 1;    var date = myDate.getDate();    var day = myDate.getDay();    switch (day) {        case 0: day = "星期日"; break;        case 1: day = "星期一"; break;        case 2: day = "星期二"; break;        case 3: day = "星期三"; break;        case 4: day = "星期四"; break;        case 5: day = "星期五"; break;        case 6: day = "星期六"; break;    }    var hour = myDate.getHours();    var minute = myDate.getMinutes();    var second = myDate.getSeconds();    if (hour < 10)        hour = "0" + hour;    if (minute < 10)        minute = "0" + minute;    if (second < 10)        second = "0" + second;    var displayValue = year + "年" + month + "月" + date + "日" + " " + day + "  " + hour + ":" + minute + ":" + second;    document.getElementById(XelementID).innerHTML = displayValue;    var t = setTimeout(function(){displayDateTime(XelementID);}, 500);}</script></head><body>    <div id="div1"></div>    <script>displayDateTime("div1")</script></body></html>
  相关解决方案