JavaScript Date setDate() method
- Previous Page prototype
- Next Page setFullYear()
- Go to Parent Directory JavaScript Date Reference Manual
Definition and usage
setDate()
The method sets the day of the month to the date object.
Example
Example 1
Set the date in the month:
var d = new Date(); d.setDate(15);
Example 3
Set the day of the current month to the last day of the previous month:
var d = new Date(); d.setDate(0);
Example 3
Set the day of the month to a specified date:
var d = new Date("July 21, 1983 01:15:00"); d.setDate(15);
Syntax
Date.setDate(day)
Parameter value
Parameter | Description |
---|---|
day |
Required. An integer representing the day of the month. Expected value is 1-31, but other values are allowed:
If a month has 31 days:
If a month has 30 days:
|
Technical details
Return value: | A number representing the milliseconds between the date object and midnight on January 1, 1970. |
---|---|
JavaScript version: | ECMAScript 1 |
browser support
method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
setDate() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Date
Tutorial:JavaScript Date Format
Tutorial:JavaScript Date Setting Methods
- Previous Page prototype
- Next Page setFullYear()
- Go to Parent Directory JavaScript Date Reference Manual