前台Json格式中时间的格式转换

 后台序列化成Json格式之后,传到前台的时间格式为:”/Date(1431069217610+0800)/”;

 前台处理:

 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:37

原文地址:https://www.cnblogs.com/Yunshine-sina/p/4533928.html