종우공간 2021. 7. 25. 11:15

Different ways to construct Date object

let birthday = new Date('9-10-1981 11:25:00');
birthday = new Date('September 10 1981');
birthday = new Date('9/10/1981');

Getting data from Data object

let val;
const today = new Date();

val = today.getMonth();
val = today.getDate();
val = today.getDay();
val = today.getFullYear();
val = today.getHourts();
val = today.getMinutes();
val = today.getSeconds();

- getMonth() 같은 경우에는 zero-based 이기 때문에 January: 0, ..., December: 11 처럼 작용한다.

- getDay() 같은 경우에는 Sunday 부터 시작 하기에 Sunday: 1, Monday: 2, ..., Saturday: 7 처럼 작용한다.

Setting data for Data object

birthday.setMonth(2);
bithday.setDate(12);
birthday.setFullYear(1985);

- setMonth() 같은 경우에는 zero-based 이기 때문에 January: 0, ..., December: 11 처럼 작용한다.

- setDay() 같은 경우에는 Sunday 부터 시작 하기에 Sunday: 1, Monday: 2, ..., Saturday: 7 처럼 작용한다.