getDate()
returns the day of the month (1 through 31) for the date.
getDate() |
Yes | Yes | Yes | Yes | Yes |
dateObject.getDate();
None.
A Number from 1 to 31 to represent the day of the month.
var myDate = new Date();
console.log(myDate.getDate());
The code above generates the following result.
The following code shows how to get the day of the month from a specific date.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">get</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from ww w.ja v a 2 s .c o m-->
var d = new Date("July 21, 1976 02:34:56");
var n = d.getDate()
document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>
The code above is rendered as follows: