标签:
效果图
首先在页面上定义一个存放日期的控件
<span id="time"></span>
JS方法
//显示当前时间日期,id表明在哪里显示
admin_index.showTime = function(id) {
var today = new Date();
var time = today.getFullYear() + "年"
+ admin_index.timeFormat(today.getMonth() + 1) + "月"
+ admin_index.timeFormat(today.getDate()) + "日 "
+ admin_index.getWeek() + " "
+ admin_index.timeFormat(today.getHours()) + ":"
+ admin_index.timeFormat(today.getMinutes()) + ":"
+ admin_index.timeFormat(today.getSeconds());
$("#" + id).text(time);
};
获取星期几
admin_index.getWeek = function() {
var day = new Date().getDay();
if (day == "0") return "星期天";
if (day == "1") return "星期一";
if (day == "2") return "星期二";
if (day == "3") return "星期三";
if (day == "4") return "星期四";
if (day == "5") return "星期五";
if (day == "6") return "星期六";return "";
};
格式化时间显示
admin_index.timeFormat = function(value) {
if (value >= 10) return value;
return "0" + value;
};
最后调用showTime()
//页面加载完成之后的操作
$(document).ready(function() {
//显示时间
setInterval(function(){admin_index.showTime("time");}, 1000);
});
标签:
原文地址:http://www.cnblogs.com/ywlaker/p/4757838.html