diff --git a/src/@core/utils/index.ts b/src/@core/utils/index.ts index 77926f78..111815c6 100644 --- a/src/@core/utils/index.ts +++ b/src/@core/utils/index.ts @@ -31,3 +31,29 @@ export const isToday = (date: Date) => { /* eslint-enable */ ) } + +export const calculateTimeDifference = (inputTime: string): string => { + + if (!inputTime) { + return ''; + } + + const inputDate = new Date(inputTime); + const currentDate = new Date(); + + const timeDifference = currentDate.getTime() - inputDate.getTime(); + const secondsDifference = Math.floor(timeDifference / 1000); + + if (secondsDifference < 60) { + return `${secondsDifference}秒`; + } else if (secondsDifference < 3600) { + const minutes = Math.floor(secondsDifference / 60); + return `${minutes}分钟`; + } else if (secondsDifference < 86400) { + const hours = Math.floor(secondsDifference / 3600); + return `${hours}小时`; + } else { + const days = Math.floor(secondsDifference / 86400); + return `${days}天`; + } +} diff --git a/src/components/cards/SubscribeCard.vue b/src/components/cards/SubscribeCard.vue index a9319e55..d66e8a82 100644 --- a/src/components/cards/SubscribeCard.vue +++ b/src/components/cards/SubscribeCard.vue @@ -1,19 +1,33 @@