给大家分享一个日期格式化的方法
formatDate(){
let date = new Date()
let year = date.getFullYear()
let month = date.getMonth()+1
let day = date.getDate()
let hours = date.getHours()
let minutes = date.getMinutes()
let seconds = date.getSeconds()
let milliseconds = date.getMilliseconds()
if(month < 10){
month = '0' + month
}
if(day < 10){
day = '0' + day
}
if(hours < 10){
hours = '0' + hours
}
if(minutes < 10){
minutes = '0' + minutes
}
if(seconds < 10){
seconds = '0' + seconds
}
return year + '年' + month + '月' + day + '日' + hours + '时' + minutes + '分' + seconds + '秒' + milliseconds + '毫秒'
}
返回的日期可以根据项目需求进行修改,或定义变量进行赋值