<span id="Timer"></span>
1 <script type="text/javascript"> 2 $(function () { 3 setInterval("GetTime()", 1000); 4 }); 5 //獲取時間並設置格式 6 function GetTime() { 7 var mon, day, now, hour, min, ampm, time, str, tz, end, beg, sec; 8 /* 9 mon = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", 10 "Sep", "Oct", "Nov", "Dec"); 11 */ 12 mon = new Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", 13 "九月", "十月", "十一月", "十二月"); 14 /* 15 day = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); 16 */ 17 day = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六"); 18 now = new Date(); 19 hour = now.getHours(); 20 min = now.getMinutes(); 21 sec = now.getSeconds(); 22 if (hour < 10) { 23 hour = "0" + hour; 24 } 25 if (min < 10) { 26 min = "0" + min; 27 } 28 if (sec < 10) { 29 sec = "0" + sec; 30 } 31 $("#Timer").html( 32 now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日" + " " + hour + ":" + min + ":" + sec 33 ); 34 //$("#Timer").html( 35 // day[now.getDay()] + ", " + mon[now.getMonth()] + " " 36 // + now.getDate() + ", " + now.getFullYear() + " " + hour 37 // + ":" + min + ":" + sec); 38 } 39 </script>
別忘了引用Jquery
顯示效果:2016年5月23 10:49:55 (PS:秒數會隨之改變)