安装
使用
import dayjs from 'dayjs'
dayjs().format('YYYY-MM-DD HH:mm:ss')
API
获取当前时间
格式化时间
dayjs().format('YYYY-MM-DD HH:mm:ss')
const time = '2020-12-31T15:00:00.000Z'
const formatTime = dayjs(time).format('YYYY-MM-DD HH:mm:ss')
获取时间戳
dayjs().valueOf()
const time = '2020-12-31T15:00:00.000Z'
const timestamp = dayjs(time).valueOf()
获取年份
获取月份
获取日期
获取小时
获取分钟
获取秒
获取毫秒
设置年份
dayjs().year(2020)
const time = '2020-12-31T15:00:00.000Z'
const formatTime = dayjs(time).year(2021).format('YYYY-MM-DD HH:mm:ss')
设置月份
设置日期(月份最大天数)
dayjs().date(31)
const time = '2020-12-31T15:00:00.000Z'
const formatTime = dayjs(time).date(30).format('YYYY-MM-DD HH:mm:ss')
设置小时