15. 날짜

유지원·2021년 6월 8일
0

JAVASCRIPT LEVEL1

목록 보기
15/19
post-thumbnail

이 포스팅은 '러닝 자바스크립트'를 보며 공부한 내용입니다.

날짜

✔️ 자바스크립트의 날짜와 시간은 내장된 Date 객체에서 담당.
Date 객체는 원래 자바에서 가져온 것.
('자바'스크립트가 자바와 연관된 몇 안 되는 부분 중 하나)


현재 날짜와 시간을 나타내는 객체를 만들 때는 new Date()를 사용.

const now = new Date();
now;                          // Fri Dec 16 2020 09:20:16 GMT +0900 (KST)

특정 날짜에 해당하는 객체를 만들 때 :
const halloween = new Date(2020, 9, 31); // 월은 0에서 시작. 9 ➜ 10.

특정 날짜와 시간에 해당하는 객체를 만들 때 :
const halloweenParty = new Date(2020, 9, 31, 19, 0); // 19:00 = 7:00 pm

날짜 객체를 만들면 아래와 같이 각 부분을 가져올 수 있습니다.
halloweenParty.getFullYear();        // 2021
halloweenParty.getMonth();           // 5
halloweenParty.getDate();            // 8
halloweenParty.getDay();             // 2 (1: 월요일, 0: 일요일)
halloweenParty.getHours();           // 12
halloweenParty.getMinutes();         // 0
halloweenParty.getSeconds();         // 0
halloweenParty.getMillisecounds();   // 0
profile
👋 https://github.com/ujw0712

0개의 댓글