Home >>JavaScript Date Object Methods >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 | 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. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
setFullYear() | Yes | Yes | Yes | Yes | Yes |
<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>
Click the button to see the Output.
<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>
Click the button to see the Output.