js/vue处理日期格式

switchTimeFormat (time) {
    
    
   const dateTime = new Date(time)
   const year = dateTime.getFullYear()
   const month = dateTime.getMonth() + 1
   const date = dateTime.getDate()
   const hour = dateTime.getHours()
   const minute = dateTime.getMinutes()
   const second = dateTime.getSeconds()
   return `${
      
      year}-${
      
      this.addZero(month)}-${
      
      this.addZero(date)} ${
      
      this.addZero(hour)}:${
      
      this.addZero(minute)}:${this.addZero(second)`
},
addZero (v) {
    
    
     return v < 10 ? '0' + v : v
 }

猜你喜欢

转载自blog.csdn.net/yxgd_1442962728/article/details/106218442