JavaScript setDate() Method allows you to set the day of the month for a given date (date object). The method takes a single argument, which is the day of the month to set.
dateObj.setDate(date_Value);
JavaScript setDate() Method
For simple example code set the day of the month to the 15th, call setDate(15)
on the Date
object:
<!DOCTYPE html>
<html>
<body>
<script>
const date = new Date(); // create a new date object
console.log(date)
date.setDate(15); // set the day of the month to the 15th
console.log(date)
</script>
</body>
</html>
Output:
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