当前位置: 代码迷 >> JavaScript >> javascript变换日期字符串为Date对象
  详细解决方案

javascript变换日期字符串为Date对象

热度:517   发布时间:2012-09-18 16:21:42.0
javascript转换日期字符串为Date对象
var   s   =   "2005-12-15   09:41:30";   
var   d   =   new   Date(Date.parse(s.replace(/-/g,   "/")));  


http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
也能实现


//stackoverflow上找到的一段代码,js中date
function printDate() {
    var temp = new Date();
    var dateStr = padStr(temp.getFullYear()) +
                  padStr(1 + temp.getMonth()) +
                  padStr(temp.getDate()) +
                  padStr(temp.getHours()) +
                  padStr(temp.getMinutes()) +
                  padStr(temp.getSeconds());
    debug (dateStr );
}

function padStr(i) {
    return (i < 10) ? "0" + i : "" + i;
}


//json形式data类型转换
var cloudNormFileDateFormat2={
  	formatDate:function(date){  
	    return dateStr = this.padStr(1900+date.year) +"-"+
               this.padStr(1 + date.month) +"-"+
               this.padStr(date.date) +" "+
               this.padStr(date.hours) +":"+
               this.padStr(date.minutes) +":"+
               this.padStr(date.seconds); 
		}, 
	padStr:function(i) {
	    return (i < 10) ? "0" + i : "" + i;
	}
}; 

  相关解决方案