代码如下:
<script type="text/javascript"> /** * 动态显示时间 精确到秒 * www.jb200.com */ function gettime() { var t = new Date(); var year = t.getFullYear(); //年 var month = t.getMonth() + 1; //月 var day = t.getDate(); //日 var hours = t.getHours(); var minutes = t.getMinutes(); var seconds = t.getSeconds(); var week = t.getDay(); var weekArr = new Array('周日','周一','周二','周三','周四','周五','周六'); week = weekArr[week]; var show_str =""; var show_str = year + "年"; if(month < 10) show_str += "0"; show_str += month + "月"; if(day < 10) show_str += "0"; show_str += day + "日 "; show_str +=(hours > 12) ? "下午 ": "上午 "; show_str += ((hours > 12) ? hours-12 : hours); show_str += ((minutes <10) ? ":0" : ":") + minutes; show_str += ((seconds <10) ? ":0" : ":") + seconds; show_str += ' '+week; $("#led_date").html(show_str); //jquery 代码 timerID = setTimeout(function(){gettime()},1000); } </script>