https://dayjs.fenxianglu.cn/
根据 utc 偏移量格式化日期
/**
* @Description: 时间戳转日期
*/
export function formatTime(
time: string | number,
flag: any,
utcOffset: string | null = null,
isShowUtc = true
): string {
const timeObj: any = {
ymd: 'YYYY-MM-DD',
ym: 'YYYY-MM',
ymdt: 'YYYY-MM-DD HH:mm:ss'
}
let date = dayjs(Number(time)).format(timeObj[flag])
if (utcOffset) {
dayjs.extend(utc)
date = dayjs(Number(time)).utcOffset(utcOffset).format(timeObj[flag])
if (isShowUtc) {
date += ' (UTC' + utcOffset + ')'
}
}
return date
}
时长计算
/**
* @description: 转化剩余天数格式
*/
export function switchRemainDate(millisecond: number) {
dayjs.extend(duration)
const days = dayjs.duration(millisecond).asDays()
console.log('🚀 ~ file: util.ts ~ line 379 ~ getDate ~ days', days)
return {
time: millisecond,
days: days
}
}