JS) Date ๊ฐ์ฒด

Ceciliaยท2022๋…„ 12์›” 19์ผ
0

JavaScript

๋ชฉ๋ก ๋ณด๊ธฐ
18/36
post-thumbnail

https://ko.javascript.info/date

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date




๐Ÿ”Date ๊ฐ์ฒด


Date ๊ฐ์ฒด๋Š” ๋‚ ์งœ์™€ ๊ด€๋ จ๋œ ๋‚ด์žฅ ๊ฐ์ฒด๋‹ค.
ํ˜„์žฌ ๋‚ ์งœ๋‚˜ ์‹œ๊ฐ„์„ ๋ณด์—ฌ์ฃผ๋Š” ์šฉ๋„ ๋“ฑ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
MDN ์™ผํŽธ์˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณด๋ฉด ๊ต‰์žฅํžˆ ๋งŽ์€ ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๋Š”๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.
์ด๋ฒˆ์—” ๊ฐ„๋‹จํžˆ new Date()๋ฅผ ์ •๋ฆฌํ•ด๋ณด์ž.





new Date()


Date ์ƒ์„ฑ์ž๋Š” ์‹œ๊ฐ„์˜ ํŠน์ • ์ง€์ ์„ ๋‚˜ํƒ€๋‚ด๋Š” Date ๊ฐ์ฒด๋ฅผ ํ”Œ๋žซํผ์— ์ข…์†๋˜์ง€ ์•Š๋Š” ํ˜•ํƒœ๋กœ ์ƒ์„ฑ๋œ๋‹ค. ๊ตฌ๋ฌธ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds)

const now = new Date();

console.log(now);
//Mon Dec 19 2022 21:35:30 GMT+0900 (ํ•œ๊ตญ ํ‘œ์ค€์‹œ)


์ด ์™ธ์—๋„ getFullYear(), getDate(), getDay(), getHours() ๋“ฑ์ด ์žˆ๋‹ค.

profile
'์ด๊ฒŒ ์ตœ์„ ์ผ๊นŒ?'๋ผ๋Š” ๊ณ ์ฐฐ์„ ํ†ตํ•ด ๋์—†์ด ์„ฑ์žฅํ•˜๊ณ , ๊ทธ ๊ณผ์ •์„ ์ฆ๊ธฐ๋Š” ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ ์ž…์žฅ์„ ์ƒ๊ฐํ•˜๋ฉฐ ์ตœ์„ ์˜ ํŽธ์˜์„ฑ์„ ์ฐพ๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€