Last active
August 1, 2020 08:57
-
-
Save YounglanHong/50fae3a9e394231704fc6a385a848c95 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
| let current = new Date() | |
| // 1. 년도 | |
| let year = current.getFullYear() // 2020 | |
| current.setFullYear(1970) | |
| year = current.getFullYear() // 1970 | |
| // 2. 월 (*️⃣ 실제 월 - 1 (1월: 0, 2월: 1 ... 12월: 11)) | |
| let month = current.getMonth() // 7 (8월) | |
| current.setMonth(11) | |
| month = current.getMonth() // 11 (12월) | |
| // 3. 날짜 | |
| let date = current.getDate() // 1 | |
| current.setDate(31) | |
| date = current.getDate() // 31 | |
| // 4. 요일 (*️⃣ 일요일부터 시작 (일: 0, 월: 1, 화: 2... 토: 6)) | |
| let day = current.getDay() // 6 | |
| current.setDay(0) | |
| day = current.getDay() // 0 | |
| // 5. 시간 | |
| (0 ~ 23) | |
| let hours = current.getHours() // 5 | |
| current.setHours(6) | |
| hours = current.getHours() // 6 | |
| (0 ~ 59) | |
| let minutes = current.getMinutes() // 40 | |
| current.setMinutes(50) | |
| minutes = current.getMinutes() // 50 | |
| (0 ~ 59) | |
| let seconds = current.getSeconds() // 50 | |
| current.setSeconds(59) | |
| seconds = current.getSeconds() // 59 | |
| // 6. 형태 변환 | |
| const date = new Date('2020/08/01/17:30'); | |
| date.toString() | |
| // "Sat Aug 01 2020 17:30:00 GMT+0900 (대한민국 표준시)" | |
| date.toDateString() | |
| // "Sat Aug 01 2020" | |
| date.toTimeString() | |
| // "17:30:00 GMT+0900 (대한민국 표준시)" | |
| date.toISOString() | |
| // "2020-08-01T08:30:00.000Z" | |
| date.toUTCString() | |
| // "Sat, 01 Aug 2020 08:30:00 GMT" | |
| date.valueOf() // 1596270600000 | |
| typeof date.valueOf() // "number" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment