JavaScript: Date.setUTCFullYear() method. In this tutorial, you will learn how to set UTC full year in javascript with an example.
setUTCFullYear() Method JavaScript
Definition:- 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
Date.setUTCFullYear(year, month, day)
Parameters of 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
Here we will take first example of setUTCFullYear method, without passing month and day:
<!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>
Result of example 1 is:
Example – 2
Here we will take the second example of setUTCFullYear method, in this example, we will pass year and month in setUTCFullYear() method.
<!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>
Result of example -2 is:
Example -3
Here we will take the third example of the setUTCFullYear method, in this example, we will pass all three parameters like year, month and day in setUTCFullYear() method.
<!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>
Result of example – 3 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.
You may like
- JavaScript: Date setUTCDate() Method
- Set UTC Month In javaScript
- JavaScript: Date.getUTCDate() Method
- getUTCmonth Method javaScript With Example
- javaScript Digital Clock with date
- JavaScript: Set Date Methods
- String Contains JavaScript | String includes() Method
- JavaScript Get Date Methods
- JavaScript Operators With Examples
- Sorting Using JavaScript Array Sort() Method
- JavaScript Replace String With Examples
- JavaScript Array splice() Method By Example
- JavaScript: Clone an Array & Object By Example
- Check the Object is Array or not in javascript
If you have any questions or thoughts to share, use the comment form below to reach us.