let myDate = new Date();
console.log(myDate === Date.now()); // true
0 -> Jan
1 -> Feb
...
11 -> Dec
let myBirth = new Date(1997, 3, 41);
console.log(myBirth) // Mon May 12 1997 00:00:00 GMT+0900 (๋ํ๋ฏผ๊ตญ ํ์ค์)
set์ผ๋ก ์์ํ๋ ๋ฉ์๋๋ค ์ฌ์ฉํ๋ฉด ์์ ํ ์ ์๋ค.
myBirth.setFullYear(2021);
toLocale~ ์ฌ์ฉํ๋ฉด ์ฌ์ฉ์ ์ปดํจํฐ์ ์ค์ ๋ ๊ตญ๊ฐ์ ๋ง๊ฒ ๋ ์ง์ ๋ณด๊ฐ ๋ํ๋๋ค.
myBirth.toLocaleDateString() //"1997. 5. 12."
myBirth.toLocaleString() //"1997. 5. 12. ์ค์ 12:00:00"
myBirth.toLocaleTimeString() //"์ค์ 12:00:00"
console.log(typeof myDate); // object
console.log(String(myDate)); // Thu May 18 2017 00:00:00 GMT+0900 (Korean Standard Time)
>console.log(Number(myDate)); // 1495033200000
console.log(Boolean(myDate)); // true
Number๋ก ํ๋ณํ ํ ๊ฐ์ .getTime()๋ฉ์๋๋ก ์ป์ ํ์์คํฌํ ๊ฐ๊ณผ ๊ฐ๋ค.
let today = new Date(2021, 10, 24);
let tomorrow = new Date(2021, 10, 25);
timeDiff = tomorrow - today;
console.log(timeDiff); // 86400000 (ms)
console.log(timeDiff / 1000) // 86400 (sec)
console.log(timeDiff / 60) // 1440 (min)
console.log(timeDiff / 60 / 60 ) // 24 (hour)
console.log(timeDiff / 60 / 60 / 24) // 1 (day)