Method one:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 function getddd(utcDate, format) { 2 var date = new Date(parseInt(utcDate.replace("/Date(", "").replace(")/", ""), 10)); 3 var year = date.getFullYear(); 4 var month = date.getMonth() + 1;// < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; 5 var currentDate = date.getDate();// < 10 ? "0" + date.getDate() : date.getDate(); 6 var hour = date.getHours(); 7 var minute = date.getMinutes(); 8 var second = date.getSeconds(); 9 var datastr = year + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second; 10 return formatDateTime(datastr, format); 11 } 12 function formatDateTime(str, format) { 13 var date = new Date(str.split("-").join("/")); 14 if (date.toString() == "NaN" || date.toString() == "Invalid Date") { return ""; } 15 var o = { 16 "M+": date.getMonth() + 1, 17 "d+": date.getDate(), 18 "h+": date.getHours(), 19 "m+": date.getMinutes(), 20 "s+": date.getSeconds() 21 }; 22 if (/(y+)/.test(format)) { 23 format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); 24 } 25 for (var k in o) { 26 if (new RegExp("(" + k + ")").test(format)) { 27 format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); 28 } 29 } 30 return format; 31 }
Method two:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
JSON返回DateTime/Date('123123123')/解决办法 functionConvertJSONDateToJSDateObject(jsondate){ vardate =newDate(parseInt(jsondate.replace("/Date(","").replace(")/",""),10)); returndate; } 只要把DateTime值传递给ConvertJSONDateToJSDateObject就可以返回Date。通过js调用。 如果想返回yyyy-MM-dd HH:mm:SS格式 ? functiongetDate(date) { varyear =date.getFullYear(); varmonth = date.getMonth() +1; varday = date.getDate(); returnyear +"-"+month +"-"+ day ; } functiongetDateTime(date) { varyear =date.getFullYear(); varmonth = date.getMonth() +1; varday = date.getDate(); varhh = date.getHours(); varmm = date.getMinutes(); varss = date.getSeconds(); returnyear +"-"+month +"-"+ day +" "+ hh+":"+ mm +":"+ss; }