English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
ThesetDate()Method, sets the day of the month for the specified date (Date) object based on local time.
The expected value is1-31, but other values are allowed:
0 represents the last day of the previous month
-1Represents the day before the last day of the previous month
If a month has31days:
32Is the first day of the next month
If a month has30 days:
32Is the second day of the next month
date.setDate(day)
var d = new Date(); d.setDate(22);Test and see‹/›
All browsers fully support the setDate() method:
Method | |||||
setDate() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
day | 1to31integer between the two dates, representing a day of the month. If the value exceeds the date range of the month, the setDate() method will update the Date object accordingly. For example, if the value is set to 0, the date will be set to the last day of the previous month. |
Return Value: | UTC 1970 Year1Month1Milliseconds between the date 00:00:00 and the given date |
---|---|
JavaScript Version: | ECMAScript 1 |
This example sets the day of the month to the last day of the previous month:
var d = new Date(); d.setDate(0);Test and see‹/›