0%

moment 配置

参考文档

基本配置

1
2
3
4
5
import 'moment/dist/locale/zh-cn'
moment.locale('zh-cn')

app.config.globalProperties.$moment = moment
moment.defaultFormat = 'YYYY-MM-DD HH:mm:ss'

特殊序列化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const hours = moment(dt).hours()

// 判断时间段(早、中、晚)
let timePeriod = ''
if (hours < 12) {
timePeriod = '早' // 0:00 ~ 11:59 为早
} else if (hours < 14) {
timePeriod = '中午' // 12:00 ~ 13:59 为中午
} else if (hours < 18) {
timePeriod = '下午' // 14:00 ~ 17:59 为下午
} else {
timePeriod = '晚' // 18:00 ~ 23:59 为晚
}

// 格式化日期为 "MM月DD日早/中午/下午/晚:HH:mm"
return moment(dt).format(`MM月DD日${timePeriod}:HH:mm`)