JavaScript date.getDate() method
The date.getDate()
method in JavaScript returns the day of the month (from 1 to 31) for a specific date object, according to local time.
Syntax:
Returns:
- A number representing the day of the month (1-31).
Example 1: Getting the Day of the Month
Output:
Explanation:
- The
getDate()
method retrieves the day of the month from theDate
object, which is 22 for October 22, 2024.
Example 2: Current Day of the Month
Output:
Explanation:
- This retrieves the current day of the month using the
getDate()
method. If today is October 22, it would return22
.
Summary:
date.getDate()
returns the day of the month (from 1 to 31) for a givenDate
object.- It reflects local time and can be used to retrieve the specific day of the month from a date.