Easy Tutorial
❮ Css Inherit Jsref Slice Array ❯

JavaScript setFullYear() Method

JavaScript Date Object

Example

Set the year to 2020:

d Output result:


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

Parameter Values

Parameter Description
year Required. A four-digit integer representing the year. Expressed in local time.
month Optional. A numeric value representing the month. Expressed in local time. Ranges from 0 to 11: -1 is the last month of the previous year<br> 12 is the first month of the next year<br> 13 is the second month of the next year
day Optional. A numeric value representing the day of the month. Expressed in local time. Ranges from 1 to 31: 0 is the last day of the previous month<br> -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 of January 1, 1970, to the adjusted date.

Technical Details

| JavaScript Version: | 1.3 | | --- | --- |


More Examples

Example

In this example, we will set the date to November 3, 2020 using setFullYear():

d Output result:

Example

Set the date to 6 months ago:

d Output result:


JavaScript Date Object

❮ Css Inherit Jsref Slice Array ❯