util.js 731 Bytes
let util = {}
util.dateFormat = function(dateTime, format = 'YYYY-MM-DD') {
  const date = new Date(dateTime)
  const config = {
    YYYY: date.getFullYear(),
    MM: appendZero(date.getMonth() + 1), //getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11)
    DD: appendZero(date.getDate()),
    HH: date.getHours(),
    mm: date.getMinutes(),
    ss: date.getSeconds()
  }
  for (const key in config) {
    format = format.replace(key, config[key])
  }
  return format
}

function appendZero(int) {
  if (int < 10) {
    return '0' + `${int}`
  } else {
    return int
  }
}
util.decimal = function(num, fixed) {
  let pow = Math.pow(10, fixed)
  return Math.round(num * pow) / pow
}
export default util