zoukankan      html  css  js  c++  java
  • JS Date

    
    创建日期
    
    new Date()
    new Date(vlaue)
    new Date(year, month[, day, [, hour][, minutes[,seconds[, millisecones]]]]])
    
    
    例子:
      new Date(1998, 11);	// js的月份是从0 开始的。 11就是12月	
    
      new Date(2001, 9, 11);	
    
      new Date(2015, 7, 12, 9, 11, 18);	 //完整的
    
    返回年月日的时间。
    <script type="text/javascript">
    	
    	var date = new Date();
    
    	function padding(number) {
    		return number < 10 ? "0" + number : number; 
    	}
    
    	function format(date) {
    		return date.getFullYear() + " - " + 
    	 	padding(date.getMonth() + 1) + " - " + 
    	 	padding(date.getDate()) + " - " + 
    	 	padding(date.getHours()) + " - " + 
    	 	padding(date.getMinutes()) + " - " + 
    	 	padding(date.getSeconds());
    	}
    
    	alert(format(date));
    </script>
    
    
    date.setXXX(); 设定
    
    setFullYear()
    setMouth()
    setDate()
    setHours()
    setMinutes()
    setSeconds()
    
    
    如果setDate(35), 就变成了 35 - 当月的长度。 加入到下个月。
    比如是8月,35,--》 9月4日。
    
    
    new Date(2001, 2, 0);		// 2001-2-28 00:00:00;
    第0天,就是上一个月的最后一天。
    
    获取一个月的天数
    <script type="text/javascript">
    	
    	function getDays(year, month) {
    		var date = new Date(year, month, 0);
    		return date.getDate();
    	}
    
    	alert("2001年2月有: " + getDays(2001, 2) + " 天。");
    	alert("2001年3月有: " + getDays(2001, 3) + " 天。");
    
    </script>
    
    
    number unix时间戳。
    var date = new Date(number);
    
    date.setTime(number);
    

     

  • 相关阅读:
    1、scala安装和基本语法
    3.12-3.16 Hbase集成hive、sqoop、hue
    3.7-3.9 HBase表属性
    3.4-3.6 依据业务需求分析HBase的表设计
    字符串匹配[原始方法]
    括号匹配[栈]
    13.A={1,2,3,5}和为10的问题
    12.回溯递归
    11.字符串{a,b}的幂集[回溯递归]
    10.N个整数中查找是否相加为K[深度搜索]
  • 原文地址:https://www.cnblogs.com/hgonlywj/p/4907236.html
Copyright © 2011-2022 走看看