Parameter: This method accepts a single parameter as mentioned above and described below:
- date_Value: It returns the new i.e updated date of the month which is set by the setDate() method. The date of the month is an integer value ranging from 1 to 31.
Return value: This method return the number of milliseconds between the date object and midnight of January 1, 1970
Note: DateObj is a valid Date object created using Date() constructor in which we want to set the date of a month.
Below is an example of Date setDate() method.
More codes for the above method are as follows:
Example 2: Here as we know the date of the month, lies between 1 to 31 but if we suppose to set the date as 33, it will set date 2 for the next month because, and this date 2 becomes the date for the next of the previous month. In the below output, 2 is the date of November month and 10 is the month of November because the month name starts from 0 to 11 i.e, 0 for January and 11 for December.
Example 3: If in the Date() constructor we do not give any date of the month, still setDate() method set a new date which is given as its parameter.
Example 4: If nothing as a parameter is given in the Date() constructor, still the setDate() method sets the date but the month becomes the current month.
13 10 //current month
Example 5: If the new date of the month is set to zero (0), the new date will be set to the last day of the previous month.
- Google Chrome
- Internet Explorer
- Mozilla Firefox
Please Login to comment...