後臺序列化成Json格式以後,傳到前臺的時間格式爲:」\/Date(1431069217610+0800)\/」;json
前臺處理:spa
1 // json時間格式化 2 function ChangeDateFormat(jsondate) { 3 jsondate = jsondate.replace("/Date(", "").replace(")/", ""); 4 if (jsondate.indexOf("+") > 0) { 5 jsondate = jsondate.substring(0, jsondate.indexOf("+")); 6 } 7 else if (jsondate.indexOf("-") > 0) { 8 jsondate = jsondate.substring(0, jsondate.indexOf("-")); 9 } 10 var date = new Date(parseInt(jsondate, 10)); 11 var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; 12 var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); 13 var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); 14 var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); 15 var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); 16 return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds; 17 }
轉換以後的結果:2015-05-08 15:13:37code