- //页面前台显示
- <span id="clock" style="font-size:14px;"></span>
- /*
- * Filename: Bll.js
- * Description:js通用方法封装操作,
- * Created: 2013.06.23
- * Author : liangjw
- * Company:Copyright (C) 2013 Create Family Wealth Power By Peter
- */
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- $(document).ready(function () {
- //第一种
- showTime();
- //第二种
- var clock = new Clock();
- clock.display($("#clock"));
- });
- //////////////////////////////////////////////////////////////////////
- //显示系统当前时间处理 第一种方法:
- //////////////////////////////////////////////////////////////////////
- function showTime() {
- var myArray = new Array(7);
- var TD = new Date();
- myArray[0] = "星期日";
- myArray[1] = "星期一";
- myArray[2] = "星期二";
- myArray[3] = "星期三";
- myArray[4] = "星期四";
- myArray[5] = "星期五";
- myArray[6] = "星期六";
- weekday = TD.getDay();
- var h = TD.getHours();
- var m = TD.getMinutes();
- var s = TD.getSeconds();
- var hstr = h;
- var mstr = m;
- var istr = s;
- if (h < 10) { hstr = "0" + h };
- if (m < 10) { mstr = "0" + m };
- if (s < 10) { istr = "0" + s };
- $("#clock").innerhtml('当前时间:' + new Date().toLocaleDateString() + " " + myArray[weekday] + " " + hstr + ":" + mstr + ":" + istr);
- setTimeout(showTime, 1000);
- }
- //////////////////////////////////////////////////////////////////////
- //显示系统当前时间处理 第二种方法:
- //////////////////////////////////////////////////////////////////////
- function Clock() {
- var date = new Date();
- this.year = date.getFullYear();
- this.month = date.getMonth() + 1;
- this.date = date.getDate();
- this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
- this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
- this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
- this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
- this.toString = function() {
- return "现在时间是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
- };
- this.toSimpleDate = function() {
- return this.year + "-" + this.month + "-" + this.date;
- };
- this.toDetailDate = function() {
- return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
- };
- this.display = function(ele) {
- var clock = new Clock();
- ele.innerHTML = clock.toString();
- window.setTimeout(function() {clock.display(ele);}, 1000);
- };
- }
- //该片段来自于http://www.codesnippet.cn/detail/190620149793.html
来源: http://www.codesnippet.cn/detail/190620149793.html