MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / formatTime

Function formatTime

src/components/GraphPanel.tsx:42–68  ·  view source on GitHub ↗

* 格式化时间

(timestamp?: number)

Source from the content-addressed store, hash-verified

40 * 格式化时间
41 */
42function formatTime(timestamp?: number): string {
43 if (!timestamp) return '未知';
44
45 const date = new Date(timestamp);
46 const now = new Date();
47 const diff = now.getTime() - date.getTime();
48
49 // 1分钟内
50 if (diff < 60 * 1000) {
51 return '刚刚';
52 }
53
54 // 1小时内
55 if (diff < 60 * 60 * 1000) {
56 const minutes = Math.floor(diff / (60 * 1000));
57 return `${minutes}分钟前`;
58 }
59
60 // 24小时内
61 if (diff < 24 * 60 * 60 * 1000) {
62 const hours = Math.floor(diff / (60 * 60 * 1000));
63 return `${hours}小时前`;
64 }
65
66 // 更早
67 return date.toLocaleDateString('zh-CN', {month: 'numeric', day: 'numeric'});
68}
69
70export default function GraphPanel({
71 graphs,

Callers 1

GraphPanelFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected