import dayjs from 'dayjs'
// 计算两个时间之间的时间差
export function getTimeDuration(startTime, endTime) {
if (!startTime || !endTime) return '--'
if (startTime == endTime) return '0秒'
return dayjs.duration(dayjs(endTime).diff(dayjs(startTime))).humanize()
}
需要添加dayjs的两个插件
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration.js'
import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(duration)
dayjs.extend(relativeTime)