需求:格式化时间由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
}