From ed01ac16d3f23a9d7fcb490665f8a1999befa886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A7=98=E4=BA=BA?= <3311118881@qq.com> Date: Tue, 20 May 2025 19:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E4=BE=A7=E8=BE=B9=E6=A0=8F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E5=BC=95=E5=85=A5=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=BB=84=E4=BB=B6=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=BF=A1=E6=81=AF=E5=B1=95=E7=A4=BA=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E7=94=A8=E6=88=B7=E8=83=BD=E5=A4=9F=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=AB=99=E7=82=B9=E8=BF=90=E8=A1=8C=E7=8A=B6=E6=80=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/svg/other/timer.svg | 1 + src/components/Sidebar/RunTime/index.tsx | 41 ++++++++++++++++++++++++ src/components/Sidebar/index.tsx | 4 +++ 3 files changed, 46 insertions(+) create mode 100644 src/assets/svg/other/timer.svg create mode 100644 src/components/Sidebar/RunTime/index.tsx diff --git a/src/assets/svg/other/timer.svg b/src/assets/svg/other/timer.svg new file mode 100644 index 0000000..2ad97bc --- /dev/null +++ b/src/assets/svg/other/timer.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/Sidebar/RunTime/index.tsx b/src/components/Sidebar/RunTime/index.tsx new file mode 100644 index 0000000..bee11a1 --- /dev/null +++ b/src/components/Sidebar/RunTime/index.tsx @@ -0,0 +1,41 @@ +"use client" + +import { useState } from 'react'; +import Image from 'next/image'; +import Timer from '@/assets/svg/other/timer.svg'; + +export default () => { + const [time, setTime] = useState(1547647320000); + + const calculateTimeDifference = (startTimestamp: number) => { + const startDate = new Date(startTimestamp); + const currentDate = new Date(); + + let years = currentDate.getFullYear() - startDate.getFullYear(); + let months = currentDate.getMonth() - startDate.getMonth(); + let days = currentDate.getDate() - startDate.getDate(); + + // 处理月份和天数的进位 + if (days < 0) { + const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0); + days += lastMonth.getDate(); + months--; + } + if (months < 0) { + months += 12; + years--; + } + + return `${years}年 ${months}个月 ${days}天`; + }; + + return ( +