统一处理低版本safari浏览器Date兼容性问题

This commit is contained in:
Allen
2024-04-24 10:06:32 +08:00
parent 72088dff2e
commit e1524c26cd
6 changed files with 18 additions and 15 deletions

View File

@@ -171,6 +171,7 @@ export function formatDateDifference(dateString: string): string {
// return `${minutesDifference}分钟前`
// else
// return '刚刚'
if (!dateString)
return ''
return dayjs(dateString).fromNow()
}

View File

@@ -33,12 +33,16 @@ export function isToday(date: Date) {
)
}
// 计算时间差返回xx天/xx小时/xx分钟/xx秒
/**
* 计算时间差返回xx天/xx小时/xx分钟/xx秒
*
* @deprecated 建议使用:@core/utils/formatters.ts formatDateDifference
*/
export function calculateTimeDifference(inputTime: string): string {
if (!inputTime)
return ''
const inputDate = new Date(inputTime)
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
const currentDate = new Date()
const timeDifference = currentDate.getTime() - inputDate.getTime()
@@ -70,7 +74,7 @@ export function calculateTimeDiff(inputTime: string): string {
return ''
// 使用当前时区
const inputDate = new Date(inputTime)
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
const currentDate = new Date()
const timeDifference = currentDate.getTime() - inputDate.getTime()