Json时间格式转换问题

时间:2023-12-04 16:25:32

很多时候在数据库中取出数据,需要用Json来接收,但是接受出来的数据竟然是:/Date(1386040883000+0800)/ 这种格式。

这个时候就需要将Json格式,转换成Javascript格式,如下:

var CreateTIme = "/Date(1386040883000+0800)";
 var date = new Date(parseInt(item[i].CreateTime.replace("/Date(", "").replace(")/", ""), 10));
 date = date.getFullYear() + "-" + (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-" + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " " + (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":" + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes());

最后的结果则是:2013-12-03 11:21