//格式化时间
function fnW(str) {
var num;
str >= 10 ? num = str : num = "0" + str;
return num;
}
//获取当前时间
var timer = setInterval(function () {
var date = new Date();
var year = date.getFullYear(); //当前年份
var month = date.getMonth(); //当前月份
var data = date.getDate(); //天
var hours = date.getHours(); //小时
var minute = date.getMinutes(); //分
var second = date.getSeconds(); //秒
var day = date.getDay(); //获取当前星期几
var ampm = hours < 12 ? 'am' : 'pm';
//页面显示时间
$('#time').html(fnW(hours) + ":" + fnW(minute) + ":" + fnW(second));
$('#date').html('<span>' + year + '/' + (month + 1) + '/' + data + '</span><span>' + ampm + '</span><span>周' + day + '</span>')
}, 1000)