Created
August 1, 2020 08:45
-
-
Save YounglanHong/7b5c76bac9737fecd5a1269073c44932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 매개변수 없음(초기화) => 현재 날짜와 시간 가지는 Date 객체 | |
| let date = new Date(); | |
| // 매개변수 밀리초 => UTC로부터 밀리초만큼 경과된 Date 객체 | |
| // 1day = 86400000ms | |
| let date0 = new Date(0) // Thu Jan 01 1970 09:00:00 GMT+0900 | |
| let date1 = new Date(86400000) // Fri Jan 02 1970 09:00:00 GMT+0900 | |
| // 매개변수 dateString => dateString에 해당하는 Date 객체 | |
| let dateStr0 = new Date("Thu Jan 01 1970 00:00:00 UTC") // UTC | |
| let dateStr1 = new Date("Jan 01, 1970 09:00:00") // KST | |
| let dateStr2 = new Date("1970/01/01/09:00:00") // KST | |
| let dateStr3 = new Date("1970-01-01 09:00:00") | |
| dateStr0.getTime() === dateStr1.getTime() // true | |
| dateStr1.getTime() === dateStr2.getTime() // true | |
| dateStr2.getTime() === dateStr3.getTime() // true | |
| // 매개변수 개별 날짜와 시간 => 개별 날짜와 시간에 해당하는 Date 객체 | |
| let dateEach = new Date(1970,1,1,0,0,0,0) | |
| dateEach.getDate() === dateStr0.getDate() // true | |
| // new 연산자 없이 호출 => string 반환 | |
| let date = Date() | |
| console.log(typeof date, date) | |
| // string Sat Aug 01 2020 17:19:59 GMT+0900 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment