DateScheme = (timestamp = new Date().getTime(), format = 'Y-M-D h:m:s') => {
if (!/^[\d]{10,13}$/.test(timestamp)) {
console.error('只能格式化10,13位时间戳')
return false
}
const _time = timestamp.length === 10 ? (timestamp * 1000) : (timestamp * 1)
const date = new Date(_time)
const data = {
Y: date.getFullYear(),
M: date.getMonth() + 1,
D: date.getDate(),
h: date.getHours(),
m: date.getMinutes(),
s: date.getSeconds()
}
return format.replace(/[YMDhms]/g, function (m) {
return data[m] < 10 ? ('0' + data[m]) : data[m]
})
}
网友评论