Set the year to 2020:
The result of d will be:
The setFullYear() method sets the year (four digits) of the date object.
This method can also be used to set the month and day of month.
Method | |||||
---|---|---|---|---|---|
setFullYear() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
year | Required. A four-digit value representing the year, negative values are allowed |
month | Optional. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
Return Value: | A Number, representing the number of milliseconds between the date object and midnight January 1 1970 |
---|---|
JavaScript Version: | 1.3 |
Set the date to November 3, 2020:
The result of d will be:
Set the date to six months ago:
The result of d will be: