Javascript examples for Date:setMonth
The setMonth() method sets the month of a date object.
January is 0, February is 1, and so on.
This method can also be used to set the day of the month.
date.setMonth(month,day)
Parameter | Description |
---|---|
month | Required. An integer representing the month |
day | Optional. An integer representing the day of month |
month expected values are 0-11, but other values are allowed:
day expected values are 1-31, but other values are allowed:
A Number, representing the number of milliseconds between the date object and midnight January 1 1970
display the date after setting the date to be the last day of last month.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w. ja va 2s. c o m var d = new Date(); d.setMonth(d.getMonth(), 0); document.getElementById("demo").innerHTML = d; } </script> </body> </html>