JavaScript Date setFullYear() method

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);

try it yourself

Example 2

example

Set the date to November 3, 2020:

var d = new Date();
d.setFullYear(2020, 10, 3);

try it yourself

Example 3

Set the date to six months ago:

var d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);

try it yourself

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:

  • -1 will result in the last month of the previous year
  • 12 will result in the first month of the next year
  • 13 will result in the second month of the next year
day

optional. An integer representing the day of the month.

expected value is 1-31, but other values are allowed:

  • 0 will result in the last day of the previous month
  • -1 will result in the day before the last day of the previous month

if a month has 31 days:

  • 32 will result in the first day of the next month

if a month has 30 days:

  • 32 will result in the second day of the next month

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