常用函数
大约 1 分钟
日期格式化
//常用方法
export const dateFormat = (date: Date, format: string = 'YYYY-MM-DD HH:mm:ss') => {
if (!isDate(date)) date = new Date()
const config = {
YYYY: date.getFullYear(),
MM: date.getMonth() + 1,
DD: date.getDate(),
HH: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds()
}
for (const key in config) {
format = format.replace(key, config[key])
}
return format
}