날짜 메소드(Date Methods)를 사용하면 날짜 값 (년, 월, 일,시, 분, 초, 밀리 초(years, months, days, hours, minutes, seconds, milliseconds))을 가져오고 설정할(get and set) 수 있습니다.
Date Get Methods
get methods는 날짜의 일부를 가져오는 데 사용합니다. 다음은 가장 일반적인 방법(알파벳 순)입니다:
Method | Description |
---|---|
getDate() | Get the day as a number (1-31) |
getDay() | Get the weekday as a number (0-6) |
getFullYear() | Get the four digit year (yyyy) |
getHours() | Get the hour (0-23) |
getMilliseconds() | Get the milliseconds (0-999) |
getMinutes() | Get the minutes (0-59) |
getMonth() | Get the month (0-11) |
getSeconds() | Get the seconds (0-59) |
getTime() | Get the time (milliseconds since January 1, 1970) |
The getTime() Method
getTime()는 1970년 1월 1일 이후 밀리초의 수를 반환합니다:
Example
The getFullYear() Method
getFullYear()는 날짜의 년도를 4자리 숫자로 반환합니다:
Example
The getDay() Method
getDay()는 요일을 숫자(0-6)로 반환합니다:
Example
세계의 일부 국가에서는 주중 첫 번째 날을 “월요일”로 간주하지만, 자바 스크립트에서 주중 첫 번째 날 (0)은 “일요일”입니다.
이름 배열을 사용하면 getDay()는 요일을 이름으로 반환합니다:
Example
날짜 설정 방법 (Date Set Methods)
set methods는 날짜의 일부를 설정하는 데 사용됩니다. 다음은 가장 일반적인 방법(알파벳 순)입니다:
Method | Description |
---|---|
setDate() | Set the day as a number (1-31) |
setFullYear() | Set the year (optionally month and day) |
setHours() | Set the hour (0-23) |
setMilliseconds() | Set the milliseconds (0-999) |
setMinutes() | Set the minutes (0-59) |
setMonth() | Set the month (0-11) |
setSeconds() | Set the seconds (0-59) |
setTime() | Set the time (milliseconds since January 1, 1970) |
The setFullYear() Method
setFullYear()는 날짜 객체(date object)를 특정 날짜로 설정합니다. 이 예제는 2020년 1월 14일로 설정합니다:
Example
The setDate() Method
setDate()는 월의 일자를 설정합니다 (1-31):
Example
setDate() method는 날짜에 추가일 수(add days)를 더할 수 있습니다:
Example
일 수를 더하면, 월 또는 년이 이동됩니다. 변경된 일자는 Date 객체(object)가 자동으로 처리합니다.
날짜 입력 – Dates 분석(Date Input – Parsing Dates)
날짜 문자열이 유효하면, Date.parse() method는 이것을 밀리초(milliseconds)의 숫자로 반환합니다:
Example
그리고 밀리초의 숫자(number of milliseconds)를 사용하여 이것을 날짜 객체(object)로 변환할 수 있습니다:
Example
날짜 비교 (Compare Dates)
날짜를 쉽게 비교할 수 있습니다.
다음 예제에서는 오늘 날짜를 2100년 1월 14일과 비교합니다:
Example
자바스크립트는 0에서 11까지 월을 계산합니다. 1월은 0이고 12월은 11입니다.
UTC Date Methods
UTC 날짜 메서드는 UTC 날짜 (Universal Time Zone dates) 작업에 사용됩니다:
Method | Description |
---|---|
getUTCDate() | Same as getDate(), but returns the UTC date |
getUTCDay() | Same as getDay(), but returns the UTC day |
getUTCFullYear() | Same as getFullYear(), but returns the UTC year |
getUTCHours() | Same as getHours(), but returns the UTC hour |
getUTCMilliseconds() | Same as getMilliseconds(), but returns the UTC milliseconds |
getUTCMinutes() | Same as getMinutes(), but returns the UTC minutes |
getUTCMonth() | Same as getMonth(), but returns the UTC month |
getUTCSeconds() | Same as getSeconds(), but returns the UTC seconds |
전체 자바스크립트 날짜 참조 (Complete JavaScript Date Reference)
전체 참조 정보는 Complete JavaScript Date Reference에서 참고하세요.
이 참조(reference)에는 모든 Date 속성 및 메소드(properties and )를 자세한 설명과 함께 예제를 제시하고 있습니다.