Home >>JavaScript Date Object Methods >JavaScript setUTCFullYear() Method

JavaScript setUTCFullYear() Method

JavaScript setUTCFullYear() Method

JavaScript setUTCFullYear() method is used to set the year of a given input date object according to the universal time (UTC). UTC is the Universal Coordinated Time that is the time set by the World Time Standard. It returns a four digits integer value for dates between year 1000 and 9999.

Syntax:
Date.setUTCFullYear(year, month, day)

Parameter Values

Parameter Description
year This is a required parameter. If defines a value representing the year.
month This is an optional parameter. It defines an integer representing the month.
day This is an optional parameter. It defines an integer representing the day of month.

Browser Support

Method Chrome Edge Firefox Safari Opera
setUTCFullYear() Yes Yes Yes Yes Yes
Here is an example of JavaScript setUTCFullYear() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() 
{
  var d = new Date();
  d.setUTCFullYear(2050);
  document.getElementById("demo").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1() 
{
  var d = new Date();
  d.setUTCFullYear(2050, 06, 10);
  document.getElementById("demo1").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.