JavaScript动态显示当前时间: 2016年01月04日 时间:16:58:32 星期一
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <span id="timejs"></span> 2 <script type="text/javascript"> 3 function showLocale(objD) { 4 var str, colorhead, colorfoot; 5 var yy = objD.getYear(); 6 if (yy < 1900) yy = yy + 1900; 7 var MM = objD.getMonth() + 1; 8 if (MM < 10) MM = '0' + MM; 9 var dd = objD.getDate(); 10 if (dd < 10) dd = '0' + dd; 11 var hh = objD.getHours(); 12 if (hh < 10) hh = '0' + hh; 13 var mm = objD.getMinutes(); 14 if (mm < 10) mm = '0' + mm; 15 var ss = objD.getSeconds(); 16 if (ss < 10) ss = '0' + ss; 17 var ww = objD.getDay(); 18 if (ww == 0) colorhead = "<font color=\"#FF0000\">"; 19 if (ww > 0 && ww < 6) colorhead = "<font color=\"#373737\">"; 20 if (ww == 6) colorhead = "<font color=\"#333333\">"; 21 if (ww == 0) ww = "星期日"; 22 if (ww == 1) ww = "星期一"; 23 if (ww == 2) ww = "星期二"; 24 if (ww == 3) ww = "星期三"; 25 if (ww == 4) ww = "星期四"; 26 if (ww == 5) ww = "星期五"; 27 if (ww == 6) ww = "星期六"; 28 colorfoot = "</font>" 29 str = colorhead + yy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss + " " + ww + colorfoot; 30 return (str); 31 } 32 function tick() { 33 var today; 34 today = new Date(); 35 document.getElementById("timejs").innerHTML = showLocale(today); 36 window.setTimeout("tick()", 1000); 37 } 38 tick(); 39 </script>
你要转载么