Update NeoFetch.tsx
This commit is contained in:
parent
5a1cde43f2
commit
7c7e773af0
1 changed files with 11 additions and 22 deletions
|
|
@ -25,28 +25,17 @@ export default function NeoFetch() {
|
||||||
{(() => {
|
{(() => {
|
||||||
const startDate = new Date("2010-11-08T03:00:00+09:00");
|
const startDate = new Date("2010-11-08T03:00:00+09:00");
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
let diff = now.getTime() - startDate.getTime();
|
||||||
let diff = now - startDate;
|
|
||||||
|
const years = Math.floor(diff / (1000 * 60 * 60 * 24 * 365));
|
||||||
// 밀리초를 단순 나눗셈으로 안 하고 실제 날짜 차이로 계산
|
diff %= 1000 * 60 * 60 * 24 * 365;
|
||||||
const start = new Date(startDate);
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||||
let years = now.getFullYear() - start.getFullYear();
|
diff %= 1000 * 60 * 60 * 24;
|
||||||
|
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||||
start.setFullYear(start.getFullYear() + years);
|
diff %= 1000 * 60 * 60;
|
||||||
if (start > now) {
|
const mins = Math.floor(diff / (1000 * 60));
|
||||||
years--;
|
|
||||||
start.setFullYear(start.getFullYear() - 1);
|
return `${years} years, ${days} days, ${hours} hours, ${mins} mins`;
|
||||||
}
|
|
||||||
|
|
||||||
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`);
|
|
||||||
})()}
|
})()}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue