JavaScript Date setUTCFullYear() method

The JavaScript date setUTCFullYear() method is used to set the year for the specified date on the basis of universal time.

Syntax

The setUTCFullYear() method is represented by the following syntax:

Parameter

yearValue - It represents an integer value specifying the year.

monthValue - It is optional. It represents an integer value between 0 and 11 specifying the month.

dateValue - It is optional. It represents an integer value between 1 and 31 specifying the day of the month.

JavaScript Date setUTCFullYear() method example

Here, we will understand setUTCFullYear() method through various examples.

Example 1

Let's see an example to print the value of current and updated year.

Test it Now

Output:

Current year : 2018
Updated year : 2019

Example 2

Let's see an example to update a year of the given date.

Test it Now

Output:

Updated year : 2018

Example 3

In this example, we will also specify the particular month with the year.

Test it Now

Output:

Updated year : 2019
Next TopicJavaScript Date




Latest Courses