From b7df01c95bf03340d483b3cc4e56421abe7d9710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=94=EB=83=A5=20=28imnyang=29?= Date: Sat, 8 Nov 2025 08:06:04 +0900 Subject: [PATCH] Update NeoFetch.tsx --- src/components/NeoFetch.tsx | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/components/NeoFetch.tsx b/src/components/NeoFetch.tsx index 7bce4d3..1d4764b 100644 --- a/src/components/NeoFetch.tsx +++ b/src/components/NeoFetch.tsx @@ -25,17 +25,28 @@ export default function NeoFetch() { {(() => { const startDate = new Date("2010-11-08T03:00:00+09:00"); const now = new Date(); - let diff = now.getTime() - startDate.getTime(); - - const years = Math.floor(diff / (1000 * 60 * 60 * 24 * 365)); - diff %= 1000 * 60 * 60 * 24 * 365; - const days = Math.floor(diff / (1000 * 60 * 60 * 24)); - diff %= 1000 * 60 * 60 * 24; - const hours = Math.floor(diff / (1000 * 60 * 60)); - diff %= 1000 * 60 * 60; - const mins = Math.floor(diff / (1000 * 60)); - - return `${years} years, ${days} days, ${hours} hours, ${mins} mins`; + + let diff = now - startDate; + + // 밀리초를 단순 나눗셈으로 안 하고 실제 날짜 차이로 계산 + const start = new Date(startDate); + let years = now.getFullYear() - start.getFullYear(); + + start.setFullYear(start.getFullYear() + years); + if (start > now) { + years--; + start.setFullYear(start.getFullYear() - 1); + } + + let days = Math.floor((now - start) / (1000 * 60 * 60 * 24)); + start.setDate(start.getDate() + days); + + let hours = Math.floor((now - start) / (1000 * 60 * 60)); + start.setHours(start.getHours() + hours); + + let mins = Math.floor((now - start) / (1000 * 60)); + + console.log(`${years} years, ${days} days, ${hours} hours, ${mins} mins`); })()}