JavaScript获取时间格式

102 阅读1分钟

获取时间格式

const getNowFormatDate = (date) => {
  let sap = '-',
      year = date.getFullYear(),
      month = date.getMonth() + 1,
      strDate = date.getDate()
  if (month >= 1 && month <= 9) {
      month = '0' + month  
  }  
  if (strDate >= 0 && strDate <= 9) {
      strDate = '0' + strDate  
  }  
  let currentDate = year + sap + month + sap + strDate  
  return currentDate
}