效果图
html
<span id="time"></span>
JS
// 实时显示当前时间
$(document).ready(function () {
function showTime() {
var today = new Date;
var y = today.getFullYear();
var M = today.getMonth() + 1;
var d = today.getDate();
var w = today.getDay();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var week = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
$("#time").html(y + '年' + M + '月' + d + '日 ' + ' ' + h + ':' + m + ':' + s + ' ' + week[w]);
}
showTime(); //先调用下,否则还需一秒后才呈现
setInterval(showTime, 1000); //每1秒(1000毫秒)后调用 showTime()
})