
๐ JS์์ new Date( ) ๊ฐ์ฒด
JavaScript์์๋ Date ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ฏ๋ก ํ์ฌ ์๊ฐ ๋ฑ์ ํ์ํ ์ ์๋ค.
์๋์ฒ๋ผ new Date()๋ฅผ ํตํด ๋ ์ง ํ์ํ ์ ์๋๋ฐ ๋ฌธ์ ๋ format์ด ์ ๋๋์ง ์์๋ค๋ ์ !
export default function App() {
const date = new Date();
return <div>{date.toString()}</div>;
}

โ๏ธ Day.js๋ฅผ ์ฌ์ฉํด์ format ๋ณ๊ฒฝํ๊ธฐ
naver News API์์ ๋ ์ง๋ฅผ ๊ฐ์ ธ์์ ํ์ํ ๊ฒฝ์ฐ ์๋์ฒ๋ผ ๊ธฐ๋ณธ ํฌ๋งท์ผ๋ก ํ์๊ฐ ๋๋ค. ์ด๊ฑธ custom ํด๋ณด์!

1) Day.js ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํ๋ค.
npm install dayjs --save
2) dayjs ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ import ํด์ค๋ค.
import dayjs from 'dayjs'
3) format๋ฅผ ๋ณํํด์ค๋ค.
<span> {dayjs(date).format('YYYY-MM-DD hh:mmA')}</span>

โจ Day.js์ ๋ค์ํ format
YY | 18 | Two-digit year |
YYYY | 2018 | Four-digit year |
M | 1-12 | The month, beginning at 1 |
MM | 01-12 | The month, 2-digits |
MMM | Jan-Dec | The abbreviated month name |
MMMM | January-December | The full month name |
D | 1-31 | The day of the month |
DD | 01-31 | The day of the month, 2-digits |
d | 0-6 | The day of the week, with Sunday as 0 |
dd | Su-Sa | The min name of the day of the week |
ddd | Sun-Sat | The short name of the day of the week |
dddd | Sunday-Saturday | The name of the day of the week |
H | 0-23 | The hour |
HH | 00-23 | The hour, 2-digits |
h | 1-12 | The hour, 12-hour clock |
hh | 01-12 | The hour, 12-hour clock, 2-digits |
m | 0-59 | The minute |
mm | 00-59 | The minute, 2-digits |
s | 0-59 | The second |
ss | 00-59 | The second, 2-digits |
SSS | 000-999 | The millisecond, 3-digits |
Z | +05:00 | The offset from UTC, ยฑHH:mm |
ZZ | +0500 | The offset from UTC, ยฑHHmm |
A | AM PM | |
a | am pm |
โญ๏ธ ์ฐธ๊ณ
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
Date() ์์ฑ์ - JavaScript | MDN
Date ์์ฑ์๋ ์๊ฐ์ ํน์ ์ง์ ์ ๋ํ๋ด๋ Date ๊ฐ์ฒด๋ฅผ ํ๋ซํผ์ ์ข ์๋์ง ์๋ ํํ๋ก ์์ฑํฉ๋๋ค. Date ๊ฐ์ฒด๋ 1970๋ 1์ 1์ผ UTC(๊ตญ์ ํ์ค์) ์์ ์ผ๋ก๋ถํฐ ์ง๋ ์๊ฐ์ ๋ฐ๋ฆฌ์ด๋ก ๋ํ๋ด๋ UNIX
developer.mozilla.org
Day.js ยท 2kB JavaScript date utility library
2kB JavaScript date utility library
day.js.org
'frontEnd > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ ์ญ์ํ๊ด๋ฆฌ๋ ๋ญ๊ฐ์ข์๊น?(Redux,Zustand,Mobx) (0) | 2024.04.19 |
---|---|
3์ด์์ ํ๋ฉด ์๋จ๋ฉด ๋ ๋๋ค : CodeSplitting (1) | 2024.04.14 |
path ๊น๋ํ๊ฒ ๊ด๋ฆฌํ๊ธฐ (0) | 2024.02.05 |
์ค์๊ฐ ์ฑํ ๊ธฐ๋ฅ : Socket.io (0) | 2024.01.09 |
Return ๋ฌธ์ Hook ์๋์ชฝ์ ์์ด์ผํ๋ค :Hook ๊ท์น (2) | 2024.01.08 |

๐ JS์์ new Date( ) ๊ฐ์ฒด
JavaScript์์๋ Date ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ฏ๋ก ํ์ฌ ์๊ฐ ๋ฑ์ ํ์ํ ์ ์๋ค.
์๋์ฒ๋ผ new Date()๋ฅผ ํตํด ๋ ์ง ํ์ํ ์ ์๋๋ฐ ๋ฌธ์ ๋ format์ด ์ ๋๋์ง ์์๋ค๋ ์ !
export default function App() {
const date = new Date();
return <div>{date.toString()}</div>;
}

โ๏ธ Day.js๋ฅผ ์ฌ์ฉํด์ format ๋ณ๊ฒฝํ๊ธฐ
naver News API์์ ๋ ์ง๋ฅผ ๊ฐ์ ธ์์ ํ์ํ ๊ฒฝ์ฐ ์๋์ฒ๋ผ ๊ธฐ๋ณธ ํฌ๋งท์ผ๋ก ํ์๊ฐ ๋๋ค. ์ด๊ฑธ custom ํด๋ณด์!

1) Day.js ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํ๋ค.
npm install dayjs --save
2) dayjs ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ import ํด์ค๋ค.
import dayjs from 'dayjs'
3) format๋ฅผ ๋ณํํด์ค๋ค.
<span> {dayjs(date).format('YYYY-MM-DD hh:mmA')}</span>

โจ Day.js์ ๋ค์ํ format
YY | 18 | Two-digit year |
YYYY | 2018 | Four-digit year |
M | 1-12 | The month, beginning at 1 |
MM | 01-12 | The month, 2-digits |
MMM | Jan-Dec | The abbreviated month name |
MMMM | January-December | The full month name |
D | 1-31 | The day of the month |
DD | 01-31 | The day of the month, 2-digits |
d | 0-6 | The day of the week, with Sunday as 0 |
dd | Su-Sa | The min name of the day of the week |
ddd | Sun-Sat | The short name of the day of the week |
dddd | Sunday-Saturday | The name of the day of the week |
H | 0-23 | The hour |
HH | 00-23 | The hour, 2-digits |
h | 1-12 | The hour, 12-hour clock |
hh | 01-12 | The hour, 12-hour clock, 2-digits |
m | 0-59 | The minute |
mm | 00-59 | The minute, 2-digits |
s | 0-59 | The second |
ss | 00-59 | The second, 2-digits |
SSS | 000-999 | The millisecond, 3-digits |
Z | +05:00 | The offset from UTC, ยฑHH:mm |
ZZ | +0500 | The offset from UTC, ยฑHHmm |
A | AM PM | |
a | am pm |
โญ๏ธ ์ฐธ๊ณ
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
Date() ์์ฑ์ - JavaScript | MDN
Date ์์ฑ์๋ ์๊ฐ์ ํน์ ์ง์ ์ ๋ํ๋ด๋ Date ๊ฐ์ฒด๋ฅผ ํ๋ซํผ์ ์ข ์๋์ง ์๋ ํํ๋ก ์์ฑํฉ๋๋ค. Date ๊ฐ์ฒด๋ 1970๋ 1์ 1์ผ UTC(๊ตญ์ ํ์ค์) ์์ ์ผ๋ก๋ถํฐ ์ง๋ ์๊ฐ์ ๋ฐ๋ฆฌ์ด๋ก ๋ํ๋ด๋ UNIX
developer.mozilla.org
Day.js ยท 2kB JavaScript date utility library
2kB JavaScript date utility library
day.js.org
'frontEnd > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ ์ญ์ํ๊ด๋ฆฌ๋ ๋ญ๊ฐ์ข์๊น?(Redux,Zustand,Mobx) (0) | 2024.04.19 |
---|---|
3์ด์์ ํ๋ฉด ์๋จ๋ฉด ๋ ๋๋ค : CodeSplitting (1) | 2024.04.14 |
path ๊น๋ํ๊ฒ ๊ด๋ฆฌํ๊ธฐ (0) | 2024.02.05 |
์ค์๊ฐ ์ฑํ ๊ธฐ๋ฅ : Socket.io (0) | 2024.01.09 |
Return ๋ฌธ์ Hook ์๋์ชฝ์ ์์ด์ผํ๋ค :Hook ๊ท์น (2) | 2024.01.08 |