//时间戳 转 日期格式
timestampToDate(timestamp, format = "YYYY-MM-DD hh:mm:ss") {
const formatArr = ['YYYY', 'MM', 'DD', 'hh', 'mm', 'ss']
let date = new Date(timestamp)
const YYYY = date.getFullYear()
const MM = date.getMonth() + 1
const DD = date.getDate()
const hh = date.getHours()
const mm = date.getMinutes()
const ss = date.getSeconds()
const dateArr = [YYYY, MM, DD, hh, mm, ss]
let formatDate = format
dateArr.forEach((a, index, arr) => {
let findStr = formatArr[index]
if (formatDate.includes(findStr)) {
a = a >= 10 ? a : ('0' + a)
} else {
findStr = formatArr[index][0]
}
formatDate = formatDate.replace(findStr, a)
})
return formatDate
},
timestampToDate(new Date().getTime(),'YYYY-MM-D h:m:s')