日期格式化 最方便最简单的

300 阅读1分钟

  //日期格式化

    dateFormat(date, format = 'YYYY/MM/DD HH:mm') {

      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] < 10 ? '0' + config[key] : config[key])

      }

      return format

    },