JavaScript Date setFullYear() method
- Previous Page setDate()
- Next Page setHours()
- Go Back to the Previous Level JavaScript Date Reference Manual
Definition and usage
setFullYear()
Method to set the year of the date object (a four-digit number between 1000 and 9999).
This method can also be used to set the month and the date of the month.
example
Example 1
Set the year to 2020:
var d = new Date(); d.setFullYear(2020);
Example 2
example
Set the date to November 3, 2020:
var d = new Date(); d.setFullYear(2020, 10, 3);
Example 3
Set the date to six months ago:
var d = new Date(); d.setFullYear(d.getFullYear(), d.getMonth() - 6);
syntax
Date.setFullYear(year, month, day)
parameter value
parameter | description |
---|---|
year | required. The value representing the year, allowing negative values. |
month |
optional. An integer representing the month. expected value is 0-11, but other values are allowed:
|
day |
optional. An integer representing the day of the month. expected value is 1-31, but other values are allowed:
if a month has 31 days:
if a month has 30 days:
|
technical details
return value: | a number representing the milliseconds between the date object and midnight on January 1, 1970. |
---|---|
JavaScript version: | ECMAScript 1 |
browser support
method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
setFullYear() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Date
Tutorial:JavaScript Date Format
Tutorial:JavaScript Date Setting Methods
- Previous Page setDate()
- Next Page setHours()
- Go Back to the Previous Level JavaScript Date Reference Manual