Programing Language/Javascript

[Javascript] Date ๊ฐ์ฒด ์‚ฌ์šฉํ•˜๊ธฐ

JHeaon ใƒป 2023. 3. 22. 18:59



๐Ÿ“š Javascript์—์„œ Date ๊ฐ์ฒด 

Javascript๋Š” Date๋ผ๋Š” ๋‚ด์žฅ ๊ฐ์ฒด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ด๋Š” ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ์ €์žฅํ•˜๊ณ  ๊ทธ๊ฑธ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค.

 

 

 

๐Ÿ“š Date ์‚ฌ์šฉ

์ผ๋ฐ˜์ ์ธ Date ๊ฐ์ฒด์˜ ์ƒ์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•œ๋‹ค.

const date = new Date();
// result : "2023-03-22T09:48:29.222Z"

 

 

 

๐Ÿ“’ Date ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•œ ๋…„,์›”,์ผ ๊ตฌํ•˜๊ธฐ

const now = new Date();	// ํ˜„์žฌ ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„
const year = now.getFullYear();	// ์—ฐ๋„
const month = now.getMonth();	// ์›”
const date = now.getDate();	// ์ผ

 

๐Ÿ“’ Date ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•œ ์‹œ๊ฐ„, ๋ถ„, ์ดˆ ๊ตฌํ•˜๊ธฐ

var now = new Date();	// ํ˜„์žฌ ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„
var hours = now.getHours();	// ์‹œ๊ฐ„
var minutes = now.getMinutes();	// ๋ถ„
var seconds = now.getSeconds();	// ์ดˆ

 

 

'Programing Language/Javascript'์˜ ๋‹ค๋ฅธ๊ธ€

  • ํ˜„์žฌ๊ธ€ [Javascript] Date ๊ฐ์ฒด ์‚ฌ์šฉํ•˜๊ธฐ

๊ด€๋ จ๊ธ€