VIP失效时间格式化逻辑修改

This commit is contained in:
chen wei bo
2025-09-18 09:38:17 +08:00
parent c36ff6dc76
commit 1fa5eb7cb0
3 changed files with 18 additions and 16 deletions
+15 -13
View File
@@ -359,19 +359,21 @@ export default class Utils {
// 获取格式化字符串: vip失效时间
public static formatVipLeftTime(expiryTimestamp: number): string {
const dateNow = new Date();
const timeDiff = Math.abs(expiryTimestamp - dateNow.getTime());
const hours = Math.floor(timeDiff / (1000 * 60 * 60));
if (hours >= 24) {
return (
(hours % 24).toString() + LanguageUtils.getText("purchasepanel.day")
);
// 当前时间戳,单位:秒
const nowSeconds = Math.floor(Date.now() / 1000);
// 差值(秒)
const diffSeconds = Math.max(0, expiryTimestamp - nowSeconds);
// 转换为天、小时、分钟
const days = Math.floor(diffSeconds / (60 * 60 * 24));
const hours = Math.floor((diffSeconds % (60 * 60 * 24)) / 3600);
const minutes = Math.floor((diffSeconds % 3600) / 60);
console.log("vip失效剩余时间差(秒):", diffSeconds, "天:", days, "小时:", hours, "分钟:", minutes);
if (days > 0) {
return `${days}${LanguageUtils.getText("purchasepanel.day")}`;
}
const minutes = Math.floor((timeDiff / (1000 * 60)) % 60);
//const seconds = Math.floor((timeDiff / 1000) % 60);
return `${hours}${LanguageUtils.getText(
"purchasepanel.hour"
)}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
if (hours > 0) {
return `${hours}${LanguageUtils.getText("purchasepanel.hour")}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
}
return `${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
}
}