2 回复
1,util.js
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
const formatDate = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}
2,引入util.js
import format from 'util' //util的路径
format.formatDate(date) // date 传入的日期
觉得有帮助的话点个有用吧