This commit is contained in:
2025-10-14 15:19:12 +08:00
parent 7999c0b9ad
commit a389733596
7 changed files with 398 additions and 155 deletions
+8 -24
View File
@@ -408,37 +408,21 @@ export default class Utils {
* 格式化聊天时间显示
* @param timestamp 时间戳(毫秒),如果为null则显示"暂无聊天记录"
* @returns 格式化的时间字符串
* 格式规则:
* - 一日内:显示时和分(HH:mm)
* - 一周内:显示x天前
* - 一个月内:显示x周前
* - 一个月以上:显示"一个月以上"
* 格式规则:显示完整的年月日时分秒(例如:2025-9-17 20:40:50
*/
public static formatChatTime(timestamp: number | null): string {
if (!timestamp) {
return LanguageUtils.getText("pastgirllistpanel.nomemory");
}
const now = new Date();
const chatDate = new Date(timestamp);
const diffMs = now.getTime() - chatDate.getTime();
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
const year = chatDate.getFullYear();
const month = chatDate.getMonth() + 1;
const day = chatDate.getDate();
const hours = Utils.padStart(chatDate.getHours().toString(), 2);
const minutes = Utils.padStart(chatDate.getMinutes().toString(), 2);
const seconds = Utils.padStart(chatDate.getSeconds().toString(), 2);
if (diffDays === 0) {
// 一日内:显示时和分
const hours = Utils.padStart(chatDate.getHours().toString(), 2);
const minutes = Utils.padStart(chatDate.getMinutes().toString(), 2);
return `${hours}:${minutes}`;
} else if (diffDays < 7) {
// 一周内:显示x天前
return `${diffDays}${LanguageUtils.getText("purchasepanel.day")}`;
} else if (diffDays < 30) {
// 一个月内:显示x周前
const weeks = Math.floor(diffDays / 7);
return `${weeks}${LanguageUtils.getText("purchasepanel.week")}`;
} else {
// 一个月以上:显示"一个月以上"
return LanguageUtils.getText("purchasepanel.months");
}
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
}