JavaScript Tutorial.32

ansunny1170·2021년 12월 21일
0
post-thumbnail

JS Set Date Methods

날짜 설정 방법을 사용하면 날짜 개체에 대한 날짜값(년, 월, 일, 시, 분, 초, 밀리초)를 설정할 수 있다.

Set Date Methods

Set Date methods are used for setting a part of a date:

MethodDescription
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() 메서드는 날짜 개체의 연도를 설정합니다.
아래 예시에서 년도 까지만 설정했다:

setFullYear() 메서드는 선택적으로 월과 일을 설정할 수 있다.

The setMonth() Method

setMonth() 메서드는 날짜 객체의 월(0-11)을 설정한다.

The setDate() Method

setDate() 메서드는 날짜 객체(1-31)의 날짜를 설정한다.

setDate() 메서드를 사용하여 날짜에 날짜를 추가할 수도 있다.

일(day)을 추가하여 월 또는 연도가 이동하는 경우 변경 사항은 Date 객체에 의해 자동으로 처리된다.

The setHours() Method

setHours() 메서드는 날짜 객체의 시간(0-23)을 설정한다.

The setMinutes() Method

setMinutes() 메서드는 날짜 객체의 분(0-59)을 설정한다.

The setSeconds() Method

setSeconds() 메서드는 날짜 객체의 초(0-59)를 설정한다.

Compare Dates

날짜를 쉽게 비교할 수 있다.
아래 예시는 오늘(today) 날짜를 2100년 1월 14일과 비교하여, 결과를 출력하도록 하였다.

Complete JavaScript Date Reference

완전한 Date 참고를 위해 아래 주소를 참조하자
(참조 : https://www.w3schools.com/jsref/jsref_obj_date.asp)

profile
공정 설비 개발/연구원에서 웹 서비스 개발자로 경력 이전하였습니다. Node.js 백엔드 기반 풀스택 개발자를 목표로 하고 있습니다.

0개의 댓글