JavaScript setFullYear() method
Example
Set the year to 2020:
var d = new Date();
d.setFullYear(2020);
d Output result:
Try it »
Definition and Usage
The setFullYear() method is used to set the year.
This method can also be used to set the month and the day of the month.
Browser support





All major browsers support the setFullYear() method
Syntax
Date
.setFullYear(
year
,
month
,
day
)
Parameter value
| Parameters | Description |
|---|---|
| year | Required. A four-digit integer representing the year, expressed in local time. |
| month | Optional. A value representing the month.
Expressed in local time. An integer between 0 and 11 representing January through December. |
Expressed in local time. An integer between 1 and 31:
- 0 is the last day of the previous month
- -1 is the day before the last day of the previous month
If the current month has 31 days:
- 32 is the first day of the next month
If the current month has 30 days:
- 32 is the second day of the next month
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds from midnight January 1, 1970 to the adjusted date. |
Technical Details
| JavaScript version: | 1.3 |
|---|
More examples
Example
In this example, we set the date to November 3, 2020 using setFullYear():
var d=new Date();
d.setFullYear(2020,10,3);
d Output result:
Try it »
Example
Set the date to 6 months ago:
var d=new Date();
d.setFullYear(d.getFullYear,d.getMonth()-6);
d Output result:
Try it »
JavaScript Date object