zoukankan      html  css  js  c++  java
  • js 时间戳 中国标准时间 年月日 日期之间的转换

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title>日期格式的转换</title>
    	</head>
    	<body>
    	</body>
    	<script type="text/javascript">
    	console.log(new Date()) //获取中国标准时间      //Wed Feb 13 2019 20:15:44 GMT+0800 (中国标准时间)
    	console.log(new Date().getTime()) //标准时间变为时间戳   //1550060144673
    	
    
    
    	//将中国标准时间转换为年月日格式  ----开始
    	function formatTen(num) { 
    		return num > 9 ? (num + "") : ("0" + num); 
    	} 
    	function formatDate(date) { 
    		var year = date.getFullYear(); 
    		var month = date.getMonth() + 1; 
    		var day = date.getDate(); 
    		var hour = date.getHours(); 
    		var minute = date.getMinutes(); 
    		var second = date.getSeconds(); 
    		return year + "-" + formatTen(month) + "-" + formatTen(day); 
    	}
    	//将中国标准时间转换为年月日格式  ----结束
    	
    	
    
            //标准时间变为年月日格式的使用
    	var d1=new Date()
    	var d2=formatDate(d1)
    	console.log(d2)  //2019-02-13
    
    
    
            //在当前日期上加几天
    	function getNextDay(d,t){
    	        d = new Date(new Date(d).getTime()+(1000*60*60*24)*t);   //先把标准时间变为时间戳再计算要加的天数
    	        //格式化
    	        return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();  //转换一下格式
    	 }
    	console.log(getNextDay('2019-02-11',6))        //2019-2-17
    	</script>
    </html>
    
  • 相关阅读:
    MongoDB 数组
    MongoDB 内嵌文档
    MongoDB 聚合操作
    MongoDB 文档的删除操作
    MongoDB 文档的更新操作
    MongoDB 文档的查询和插入操作
    MongoDB 安装和可视化工具
    SSIS 容器
    SSISDB2:SSIS工程的操作实例
    Replication:distribution 中一直在运行 waitfor delay @strdelaytime 语句
  • 原文地址:https://www.cnblogs.com/lml-lml/p/10371728.html
Copyright © 2011-2022 走看看