日期格式 js

getNowTime(time) {
      const now = time
      const year = now.getFullYear() // 得到年份
      let month = now.getMonth() + 1 // 得到月份
      let date = now.getDate() // 得到日期
      let Hour = now.getHours()
      let Minute = now.getMinutes()
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      Hour = Hour.toString().padStart(2, '0')
      Minute = Minute.toString().padStart(2, '0')
      const defaultDate = `${year}-${month}-${date} ${Hour}:${Minute}`
      return defaultDate
    },
原文地址:https://www.cnblogs.com/wsj1/p/14593451.html