zoukankan      html  css  js  c++  java
  • 时钟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 "现在是:" + 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.cnblogs.com/mahaisong) 以上文章都是经过本人设计实践和阅读其他文档得出。如果需要探讨或指教可以留言或加我QQ!欢迎交流!
  • 相关阅读:
    .net中数据库事务机制
    位图排序
    JavaScript实现手动画线
    CSS 样式
    我的知识计划
    开发民政信息采集工具有感
    系统小技巧
    C++的学习笔记
    Android核心服务学习笔记
    突然想到的“社会发展历程”
  • 原文地址:https://www.cnblogs.com/mahaisong/p/2193382.html
Copyright © 2011-2022 走看看