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;
}
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章