티스토리 뷰
Date
날짜와 시간(연월일시분초밀리초)을 위한 메서드를 제공하는 빌트인 객체이자 생성자 함수
30.1 Date 생성자 함수
new Date()는 현재 날짜와 시간을 갖는 Date 객체 반환
Date()는 현재 날짜와 시간을 갖는 문자열 반환
new Date(milliseconds) 1970년 1월 1일 00:00:00(UTC) + 전달된 밀리초를 나타내는 Date 객체 반환
new Date(dateString) Date.parse 메서드에 의해 해석된 날짜와 시간을 나타내는 Date 객체 반환
new Date(year, month[, day, hour, minute, second, millisecond])
year | |
month | 0 ~ 11 |
day | 1 ~ 31 |
hour | 0 ~ 23 |
minute | 0 ~ 59 |
second | 0 ~ 59 |
millisecond | 0 ~ 999 |
30.2 Date 메서드
1. Date.now()
1970년 1월 1일 00:00:00(UTC) 기준 경과한 밀리초 반환
2. Date.parse(문자열)
인자로 전달된 날짜시간을 밀리초로 반환
3. Date.UTC(year, month[, day, hour, minute, second, millisecond])
1970년 1월 1일 00:00:00(UTC)부터 인자로 전달된 날짜시간까지를 밀리초로 반환
get | set | |
year | Date.prototype.getFullYear() Date 객체의 연도를 반환(정수) |
Date.prototype.setFullYear(year[, month, day]) Date 객체의 연도를 변경 월, 일도 설정할 수 있음 |
month | Date.prototype.getMonth() Date 객체의 월을 반환(0~11) |
Date.prototype.setMonth(month[, day]) Date 객체의 월을 변경 일도 설정할 수 있음 |
date | Date.prototype.getDate() Date 객체의 날짜를 반환(1~31) |
Date.prototype.setDate(day) Date 객체의 날짜를 변경 |
day | Date.prototype.getDay() Date 객체의 요일을 반환(0~6 일~토) |
|
hours | Date.prototype.getHours() Date 객체의 시간을 반환(0~23) |
Date.prototype.setHours(hour[, minute, second, millisecond]) Date 객체의 시간을 변경(0~23) 분, 초, 밀리초도 설정할 수 있음 |
minutes | Date.prototype.getMinutes() Date 객체의 분을 반환(0~59) |
Date.prototype.setMinutes(minute[, second, millisecond]) Date 객체의 분을 변경(0~59) 초, 밀리초도 설정할 수 있음 |
seconds | Date.prototype.getSeconds() Date 객체의 초를 반환(0~59) |
Date.prototype.setSeconds(second[, millisecond]) Date 객체의 초를 변경(0~59) 밀리초도 설정할 수 있음 |
milliseconds | Date.prototype.getMilliSeconds() Date 객체의 밀리초를 반환(0~999) |
Date.prototype.setMilliSeconds(millisecond) Date 객체의 밀리초를 변경(0~999) |
19. Date.prototype.getTime
1970년 1월 1일 00:00:00(UTC) 기준 Date 객체까지 경과된 밀리초 반환
Date.UTC와 호출 방식만 다름
20. Date.prototype.setTime
UTC 시간 + 전달된 밀리초로 Date 객체 설정
21. Date.prototype.getTimezoneOffset
UTC와 locale 시간의 차이를 분 단위로 반환
22. Date.prototype.toDateString
Date 객체의 날짜를 문자열로 반환(연월일요일)
23. Date.prototype.toTimeString
Date 객체의 시간을 문자열로 반환
24. Date.prototype.toISOString
Date 객체의 날짜와 시간을 ISO 8601 형식 문자열로 반환
new Date(); // Sun Aug 11 2024 23:26:51 GMT+0900 (한국 표준시)
new Date().toISOString(); // '2024-08-11T14:26:51.003Z'
25. Date.prototype.toLocaleString
Date 객체의 날짜와 시간을 인수로 전달한 locale 기준으로 표현한 문자열 반환
인수 생략 시 브라우저가 동작 중인 시스템의 locale 적용
26. Date.prototype.toLocaleTimeString
Date 객체의 시간을 인수로 전달한 locale 기준으로 표현한 문자열 반환
인수 생략 시 브라우저가 동작 중인 시스템의 locale 적용
'책' 카테고리의 다른 글
[딥다이브] 32. String (0) | 2024.08.13 |
---|---|
[딥다이브] 31. RegExp (0) | 2024.08.13 |
[딥다이브] 29. Math (0) | 2024.08.06 |
[딥다이브] 28. Number (0) | 2024.08.06 |
[딥다이브] 27. 배열(2) (0) | 2024.08.04 |