對后臺返回的時間戳 在js中進行格式化

第一步:在 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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容