跳至主要內容

常用函数

大约 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
}

重复数据进行特殊标识

文字高亮显示