第一步:在 js中先寫一個方法(如下)
Date.prototype.Format = function(format){
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
第二步:在需要對時間格式化的地方加上new Date(data).Format("yyyy-MM-dd hh:mm:ss");
注意:data? 為后臺返回的時間戳
參考http://blog.csdn.net/u012906938/article/details/41848877
自己的例子? 頁面為webschoolht 項目下 views 文件夾下的 feature 文件夾下的 art_activity.jsp
? ? ? ? ? ? ? ? ? ? js為 js 文件夾下build 文件夾下的 js 文件夾下的feature 文件夾下的 art_activity.js