zoukankan      html  css  js  c++  java
  • JS获取当前日期时间

    		//取得系统日期
    		function nowDatetime() {
    		
    			var date = new Date();
    			var month = (date.getMonth()+1) > 9 ? (date.getMonth()+1) : "0" + (date.getMonth()+1);
    			var day = (date.getDate()) > 9 ? (date.getDate()) : "0" + (date.getDate());
    			var hours = (date.getHours()) > 9 ? (date.getHours()) : "0" + (date.getHours());
    			var minutes = (date.getMinutes()) > 9 ? (date.getMinutes()) : "0" + (date.getMinutes());
    			var seconds = (date.getSeconds()) > 9 ? (date.getSeconds()) : "0" + (date.getSeconds());
    			
    			var dateString = 
    				date.getFullYear() + "/" + 
    			    month + "/" + 
    			    day + " " + 
    			    hours + ":" + 
    			    minutes + ":" + 
    			    seconds;
    			    
    			return dateString;  
    		}
    var date = new Date();  
    date.getYear();        //获取当前年份(2位)  
    date.getFullYear();    //获取完整的年份(4位,2014)  
    date.getMonth();       //获取当前月份(0-11,0代表1月)  
    date.getDate();        //获取当前日(1-31)  
    date.getDay();         //获取当前星期X(0-6,0代表星期天)  
    date.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)  
    date.getHours();       //获取当前小时数(0-23)  
    date.getMinutes();     //获取当前分钟数(0-59)  
    date.getSeconds();     //获取当前秒数(0-59)  
    date.getMilliseconds();    //获取当前毫秒数(0-999)  
    date.toLocaleDateString();     //获取当前日期   如 2014年6月25日   
    date.toLocaleTimeString();     //获取当前时间   如 下午4:45:06  
    date.toLocaleString();         //获取日期与时间 如 2014年6月25日 下午4:45:06  
    
  • 相关阅读:
    cz_health_day07
    cz_health_day06
    mysql索引底层原理
    cz_health_day05
    redis无法获取连接原因分析
    cz_health_day04
    cz_health_day03
    cz_health_day02
    cz_health_day01
    Spring学习
  • 原文地址:https://www.cnblogs.com/puxian/p/5123674.html
Copyright © 2011-2022 走看看