安装dayjs依赖包
import dayjs from 'dayjs'
export const formatDate = (value, format = 'YYYY-MM-DD') => {
if (value) {
let date = new Date(value)
return dayjs(date).format(format)
} else {
return null
}
}
export const formatTime = (value, format = 'HH:mm:ss') => {
return formatDate(value, format)
}
export const formatDateTime = (value, format = 'YYYY-MM-DD HH:mm') => {
return formatDate(value, format)
}
export const formatDateMonthTime = (value, format = 'YYYY-MM') => {
return formatDate(value, format)
}
export const formatDateYearTime = (value, format = 'YYYY') => {
return formatDate(value, format)
}
export const formatFullDateTime = (value, format = 'YYYY-MM-DD HH:mm:ss') => {
return formatDate(value, format)
}
export const formatFullDateTime59 = (value, format = 'YYYY-MM-DD HH:mm:ss') => {
if (value) {
value = new Date(value.toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1
}
return formatDate(value, format)
}