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);
    

     

  • 相关阅读:
    mysql view
    单点登录原理与简单实现
    复述记忆法
    英语细节锦集(基本时态的构成、元音辅音字母、)
    被动语态 动词的过去分词
    play后面加the不加the如何分辨
    正则表达式入门
    使用 lxml 中的 xpath 高效提取文本与标签属性值
    Android Studio 导入新工程项目
    winfrom Panel 问题
  • 原文地址:https://www.cnblogs.com/hgonlywj/p/4907236.html
Copyright © 2011-2022 走看看