Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript setFullYear() method

JavaScript setFullYear() method

Date Object Reference JavaScript Date object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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.

  • -1 is the last month of the previous year
  • 12 is the first month of next year
  • 13 is the second month of next year
  • | | *day* | Optional. A value representing the day of the month.

    Expressed in local time. An integer between 1 and 31:

    If the current month has 31 days:

    If the current month has 30 days:

    |

    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 »


    Date Object Reference JavaScript Date object