728x90
๋ฐ์ํ
ํ์์ ์ํด์ ๊ตฌ๊ธ๋ง์ ์์ฒญํด์ ์ฐพ์๋ธ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ ๋งต! ใ ใ
365์ผ์ ์ด๋ก ํ์ฐํด์ ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ์ด๋ค.
export const mapTime = timestamp => {
const seconds = Math.floor((new Date() - timestamp * 1000) / 1000);
// ํ์ฐ๋ ์ด๋ฅผ 365์ผ์ ์ด๋ก ํ์ฐํ ๊ฒ์ผ๋ก ๋๋๋ค~
let interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return `${interval} years`;
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return `${interval} months`;
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return `${interval} days`;
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return `${interval} hours`;
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return `${interval} minutes`;
}
return `${Math.floor(seconds)} seconds`;
};
728x90
'๊ฐ๋ฐ > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์๋ฐ์คํฌ๋ฆฝํธ] js vs jsx ? ํ์ฅ์ ๋ญ๊ฐ ๋ค๋ฅด์ง? (0) | 2022.12.30 |
---|---|
Fetch API - ์ด๋ฏธ์ง fetchingํ๊ธฐ (0) | 2022.09.28 |
http Content-Type : application/x-www-form-urlencoded (0) | 2022.09.19 |
[์๋ฐ์คํฌ๋ฆฝํธ ] 2์ฐจ์ ๋ฐฐ์ด ์ค๋ณต ์ ๊ฑฐํ๊ธฐ (0) | 2022.04.09 |
[JavaScript] ๋ชจ๋ ์๋ฐ์คํฌ๋ฆฝํธ data ์ ์ฅ ๋ฐฉ์(Array, object, map, set) (0) | 2022.02.19 |