
getDate() 메서드는 Date 객체의 일(day) 값을 반환합니다.
#hostingforum.kr
javascript
const currentDate = new Date();
const day = currentDate.getDate();
console.log(day); // 20
위 코드에서 currentDate 변수는 현재 날짜와 시간을 나타내는 Date 객체를 생성합니다. getDate() 메서드를 사용하여 currentDate 객체의 일(day) 값을 day 변수에 저장한 후, console.log() 함수를 사용하여 day 변수의 값을 출력합니다.
getDate() 메서드는 1에서 31까지의 일(day) 값을 반환합니다.
#hostingforum.kr
javascript
const currentDate = new Date('2024-03-20');
const day = currentDate.getDate();
console.log(day); // 20
위 코드에서 currentDate 변수는 2024년 3월 20일 날짜를 나타내는 Date 객체를 생성합니다. getDate() 메서드를 사용하여 currentDate 객체의 일(day) 값을 day 변수에 저장한 후, console.log() 함수를 사용하여 day 변수의 값을 출력합니다.
getDate() 메서드는 Date 객체의 일(day) 값을 반환하므로, 사용 시 일(day) 값을 얻기 위한 Date 객체를 생성하거나, 이미 생성된 Date 객체를 사용하여 getDate() 메서드를 호출하면 됩니다.
2025-03-21 07:52