vue中添加时间格式化函数

需求:格式化时间由2020-04-14 17:21:26-->2020年04月14日 17:21:26

调用方式:

代码:

formatDate(value) {
      var date = new Date(value)
      var year = date.getFullYear()
      var month = this.padDate(date.getMonth() + 1)
      var day = this.padDate(date.getDate())
      var hours = this.padDate(date.getHours())
      var minutes = this.padDate(date.getMinutes())
      var seconds = this.padDate(date.getSeconds())
      return year + '年' + month + '月' + day + '日' + ' ' + hours + ':' + minutes + ':' + seconds
    },
    // 在月份、日期、小时等小于10前面补0
    padDate(value) {
      return value < 10 ? '0' + value : value
    }

 


版权声明:本文为qq_40244391原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。