/Date(1555554794000)/ 转换为日期格式

时间:2023-03-10 02:13:27
/Date(1555554794000)/ 转换为日期格式

第一种方法

/Date(1555554794000)/ 转换为 2019/4/18

new Date(parseInt('/Date(1555554794000)/'.substr(6, 13))).toLocaleDateString();

/Date(1555554794000)/ 转换为 2019/4/18 上午10:33:14

new Date(parseInt('/Date(1555554794000)/'.substr(6, 13))).toLocaleString()

/Date(1555554794000)/ 转换为 上午10:33:14

new Date(parseInt('/Date(1555554794000)/'.substr(6, 13))).toLocaleTimeString()

第二种方法

//日期格式化
function ChangeDateFormat(jsondate) {
jsondate = jsondate.replace("/Date(", "").replace(")/", "");
if (jsondate.indexOf("+") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("+"));
}
else if (jsondate.indexOf("-") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("-"));
}
var date = new Date(parseInt(jsondate, 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second = date.getMilliseconds() / 1000 < 10 ? "0" + parseInt(date.getMilliseconds() / 1000) : parseInt(date.getMilliseconds() / 1000);
return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + second;
};