You can use the Date object in JavaScript to get the day of the month. The getDate() method returns the day of the month (from 1 to 31) for the specified date according to local time.
var date = new Date().getDate();
JavaScript gets a day-of-month example
Simple example code getting the current day of the month.
<!DOCTYPE html>
<html>
<body>
<script>
const now = new Date();
const dayOfMonth = now.getDate();
console.log("Day of Month", dayOfMonth);
</script>
</body>
</html>
Output:
![JavaScript get day of month](https://i0.wp.com/tutorial.eyehunts.com/wp-content/uploads/2023/04/JavaScript-get-day-of-month.jpg?resize=256%2C127&ssl=1)
You can also pass a specific date to the Date
constructor to get the day of the month for that date:
const date = new Date('2022-12-25'); const dayOfMonth = date.getDate(); console.log(dayOfMonth); // Output: 25
Do comment if you have any doubts or suggestions on this Js date object topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version