The setDate() method sets the day of the month to the date object.
The setDate() method sets the day of the month to the date object.
Date.setDate(day)
Parameter | Require | Description |
---|---|---|
day | Required. | An integer representing the day of a month. |
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
Set the day of the month:
//display the date after changing the day of the month. var d = new Date(); d.setDate(15);/*from w ww . ja v a2s . co m*/ console.log(d); //Set the day of the month to be the last day of the previous month: d.setDate(0); console.log(d); //Set the day of the month, to a specified date: var d = new Date("July 21, 2010 01:15:00"); d.setDate(15); console.log(d);