后端Json序列化日期变量时:
日期类型变量可能转换成如下格式:\"\\\/Date(1568131200000)\\\/\";
前端接收到的该日期变量格式:/Date(1568044800000)/;
故可以通过TransDate()函数将其转换为正常日期格式显示,如:2019-09-11 00:00:00。
function TransDate(time) {
if (time!= null) {
var date = new Date(parseInt(time.replace("/Date(", "").replace(")/", ""), 10));
//月份为0-11,所以+1,月份小于10时补个0
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;
}
return "";
}