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!欢迎交流!
  • 相关阅读:
    [摘录]C++ GUI库大全
    ascii 表
    ubuntu 7.04 Feisty Fawn 安装手记之二:基本配置
    二叉排序树之删除结点
    二叉树与数组
    二叉树删除,重建,交换
    二叉树判断相等,复制
    链表扩展是否有环及环的第一个结点
    二分查找
    二叉排序树之按大小遍历
  • 原文地址:https://www.cnblogs.com/mahaisong/p/2193382.html
Copyright © 2011-2022 走看看