js 时间戳转时间格式

时间:2023-03-09 15:08:20
js 时间戳转时间格式

$("#showbidMessage").append(<span>' + ChangeDateFormat(rows[i].createTime) + '</span>)         //调用

//时间转换

function ChangeDateFormat(val) {
if (val != null) {
var date = new Date(parseInt(val.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 hh = date.getHours(); //时
var mm = date.getMinutes(); //分
var ss = date.getSeconds();
if (hh < 10) hh += "0";
if (mm < 10) mm += '0';
if (ss < 10) ss += '0';

return date.getFullYear() + "-" + month + "-" + currentDate + " " + hh + ":" + mm + ":" + ss;
}
return "";
}