VIP失效时间格式化逻辑修改
This commit is contained in:
@@ -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")}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user