国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JS控制日期顯示的小例子

2019-11-20 21:35:56
字體:
來源:轉載
供稿:網(wǎng)友

我們在項目中一般會遇到顯示時間的問題,一般的處理方式是在前臺通過JS控制,JS控制顯示時間的代碼如下,各種不同的顯示方式:

復制代碼 代碼如下:

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 "現(xiàn)在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
 };//現(xiàn)在是<SPAN id=clock>現(xiàn)在是:2013年3月6日 13:54:17 星期三</SPAN>

復制代碼 代碼如下:

<SPAN></SPAN>
 this.toSimpleDate = function() {
  return this.year + "-" + this.month + "-" + this.date;
 };//2013-03-06

 this.toDetailDate = function() {
  return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
 };//2013-03-06 13:45:43

 this.display = function(ele) {
  var clock = new Clock();
  ele.innerHTML = clock.toString();//顯示方式調用
  window.setTimeout(function() {clock.display(ele);}, 1000);
 };
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 岳普湖县| 区。| 岐山县| 通化县| 泽库县| 烟台市| 洛川县| 克山县| 峡江县| 申扎县| 马边| 陕西省| 盱眙县| 磴口县| 庆城县| 光山县| 平乡县| 白朗县| 丰顺县| 广宗县| 郴州市| 玛曲县| 新巴尔虎左旗| 大足县| 武邑县| 句容市| 宜黄县| 青阳县| 庆安县| 阳高县| 潼关县| 商城县| 宁陵县| 彰化县| 若尔盖县| 谢通门县| 许昌市| 枞阳县| 内乡县| 南昌县| 余干县|