$(document).ready(function(){ display(); }) function display() { var time = new Date(); //获得当前时间 var week = "日一二三四五六".charAt(time.getDay()); var year = time.getYear() + 1900; var month = time.getMonth() + 1;
//获得小时、分钟、秒 var hour = time.getHours(); var minute = time.getMinutes(); var second = time.getSeconds(); if(minute < 10){ minute="0"+minute;} if(second < 10){ second = "0"+second; } var innerHTML = year + "年" + month + "月" + time.getDate() + "日 " + hour + ":" + minute + ":" + second + " " + "星期" + week; $("#nowTime").html(innerHTML); setTimeout("display()", 1000); }