Skip to content

Commit 078c14c

Browse files
committed
feat: show comment time
1 parent 7111896 commit 078c14c

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/App.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@
8989
font-size: 14px;
9090
color: var(--text1);
9191
}
92+
93+
#comment-search-root .comment-item-time {
94+
color: var(--text3);
95+
margin-top: 4px;
96+
}

src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRef, useState } from 'react'
22
import { fetchComments } from './api'
33
import { Reply } from './reply'
4-
import { extractVideoId } from './utils'
4+
import { extractVideoId, formatDateTime } from './utils'
55

66
import './App.css'
77

@@ -81,6 +81,9 @@ const CommentTree: React.FC<CommentProps> = ({ comments, sub = false }) => {
8181
<span className='comment-item-message'>
8282
{comment.content.message}
8383
</span>
84+
<div className='comment-item-time'>
85+
{formatDateTime(comment.ctime)}
86+
</div>
8487
<CommentTree comments={comment.replies} sub />
8588
</div>
8689
</li>

src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ export function extractVideoId(url: string) {
2020
}
2121
return match[1]
2222
}
23+
24+
export function formatDateTime(ts: number) {
25+
const date = new Date(ts * 1000)
26+
return date.toLocaleString('zh-CN', {
27+
year: 'numeric',
28+
month: '2-digit',
29+
day: '2-digit',
30+
hour: '2-digit',
31+
minute: '2-digit',
32+
hour12: false,
33+
})
34+
}

0 commit comments

Comments
 (0)