1、时间戳 格式化 为字符串
export const formatDate = function (datetime, str = '-') {
function add0(m) {
return m < 10 ? '0' + m : m
}
if (!datetime) return
var date = new Date(datetime);
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
var h = date.getHours();
var mm = date.getMinutes();
var s = date.getSeconds();
return {
dateTime: y + str + add0(m) + str + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s), //yyyy-MM-dd hh:mm:ss
dateTimeMM: y + str + add0(m) + str + add0(d) + ' ' + add0(h) + ':' + add0(mm), //yyyy-MM-dd hh:mm
dateDay: y + str + add0(m) + str + add0(d), //yyyy-MM-dd
};
}
2、字符串 格式化 为时间戳
export const formatDateInt = function (timeStr) {
const dateStr = timeStr.replace(" ", "T")
const date = new Date(dateStr)
return date.getTime()
}