JavaScript setFullYear()Method
Definition and Usage
The setFullYear() method is used to set the year.
This method can 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 Values
| Parameter | Description |
|---|---|
| year | Required. A four-digit integer representing the year. Expressed in local time. |
| month | Optional. A number representing the month. Expressed in local time. An integer value between 0 and 11, representing January to December.
|
| day | Optional. A number representing the day of the month. Expressed in local time. An integer between 1 and 31:
If the month has 31 days:
If the month has 30 days:
|
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds between midnight January 1, 1970 and the adjusted date. |
Technical Details
| JavaScript Version: | 1.3 |
|---|
More Examples
Example
In this example, we will set the date to November 3, 2020 with setFullYear():
var d=new Date();
d.setFullYear(2020,10,3);
d.setFullYear(2020,10,3);
dOutput:
Try it Yourself »
Example
Set the date to 6 months ago:
var d=new Date();
d.setFullYear(d.getFullYear,d.getMonth()-6);
d.setFullYear(d.getFullYear,d.getMonth()-6);
dOutput:
Try it Yourself »
Other Extensions
JavaScript Date Object