JavaScript: Date.setUTCFullYear() method; Through this tutorial, i am going to share with you how to set UTC full year in JavaScript using setUTCFullYear() with the help of examples.
JavaScript setUTCFullYear() Method
The javascript setUTCfullYear() method, which is used to sets the full year for a specified date according to Universal Time (UTC). This method accepts three-parameter values.
Syntax of JavaScript setUTCFullYear() Method
Date.setUTCFullYear(year, month, day)
Parameters of JavaScript setUTCFullYear() Method
Parameter | Description |
---|---|
year | This is a first parameter and required. In this method year, negative values are allowed |
month | This is a second parameter and optional. You can pass values integer value from 0-11 in this parameter |
day | This is a third parameter and optional. You can pass values integer value from 1-31 in this parameter. |
Example 1 of JavaScript setUTCFullYear() Method
Let’s take first simple example using setUTCFullYear method; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript date.setUTCFullYear</title> </head> <body> <script type = "text/javascript"> var date = new Date(); date.setUTCFullYear(2025); document.write( "setUTCFullYear with year parameter: " + date ); </script> </body> </html>
Output of the above given code is:
Example 2 of JavaScript setUTCFullYear() Method
Let’s take an second example using setUTCFullYear method; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript date.setUTCFullYear with month</title> </head> <body> <script type = "text/javascript"> var date = new Date(); date.setUTCFullYear(2025, 9); document.write( "year, month parameter in setUTCFullYear() : " + date ); </script> </body> </html>
Output of the above given code is:
Example 3 of JavaScript setUTCFullYear() Method
Let’s take an third example using the setUTCFullYear method; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript date.setUTCFullYear with year, month and day</title> </head> <body> <script type = "text/javascript"> var date = new Date(); date.setUTCFullYear(2025, 9, 12); document.write( "year, month and day parameter in setUTCFullYear() : " + date ); </script> </body> </html>
Output of the above code is
Conclusion
In this javascript tutorial, you have learned how to sets a full year with year, month and day parameters using setUTCFullYear function with example.
Be First to Comment