mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-25 18:46:23 +00:00
feat: 添加日期格式化功能,支持不同年份显示完整日期;在评论项中添加调试日志Close #18
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 17s
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 17s
This commit is contained in:
@ -51,6 +51,8 @@ export function CommentItem(
|
||||
const [replies, setReplies] = useState<Comment[]>([]);
|
||||
const [repliesLoaded, setRepliesLoaded] = useState(false);
|
||||
|
||||
console.log(comment)
|
||||
|
||||
const handleToggleLike = () => {
|
||||
if (!canClickLike) {
|
||||
return;
|
||||
@ -175,6 +177,7 @@ export function CommentItem(
|
||||
unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") }
|
||||
})}</span>
|
||||
{commentState.createdAt !== commentState.updatedAt &&
|
||||
(new Date(commentState.updatedAt).getTime() - new Date(commentState.createdAt).getTime()) > 10000 &&
|
||||
<span className="text-xs">{t("edit_at", {
|
||||
time: formatDateTime({
|
||||
dateTimeString: commentState.updatedAt,
|
||||
|
0
web/src/types/datetime.ts
Normal file
0
web/src/types/datetime.ts
Normal file
@ -40,13 +40,17 @@ export function formatDateTime({
|
||||
return getAgoString(diff, unitI18n);
|
||||
}
|
||||
|
||||
if (now.getFullYear() !== date.getFullYear()) {
|
||||
// 不同年,显示完整日期时间
|
||||
return date.toLocaleString(locale, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
|
||||
return date.toLocaleString(locale, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user