若此时的时间格式为
则使用 createTime = new Date(createTime); 将时间转换为中国标准时间
private formatDate(date) {
let formatDate;
formatDate = new Date(date);
formatDate =
formatDate.getFullYear() +
"-" +
(formatDate.getMonth() + 1 > 9
? formatDate.getMonth() + 1
: "0" + (formatDate.getMonth() + 1)) +
"-" +
(formatDate.getDate() > 9
? formatDate.getDate()
: "0" + formatDate.getDate()) +
" " +
(formatDate.getHours() > 9
? formatDate.getHours()
: "0" + formatDate.getHours()) +
":" +
(formatDate.getMinutes() > 9
? formatDate.getMinutes()
: "0" + formatDate.getMinutes()) +
":" +
(formatDate.getSeconds() > 9
? formatDate.getSeconds()
: "0" + formatDate.getSeconds());
return formatDate;
}
效果图