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

JavaScript setFullYear() Method

JavaScript setFullYear() Method

JavaScript setFullYear() method is used to set the year of the date object. It returns a four digits integer value for dates between 1000 and 9999. It can also be used to set the month and day of the month.

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

Parameter Values

Parameter Description
year This is a required parameter. It 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
setFullYear() Yes Yes Yes Yes Yes
Here is an example of JavaScript setFullYear() 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.setFullYear(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.setFullYear(2050, 10, 24);
  document.getElementById("demo1").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads