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:
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