![]() |
VOOZH | about |
The date.setUTCFullYear() method is used to set year into a date object according to universal time which is created using date() constructor.
Syntax:
DateObj.setUTCFullYear(year_Value);
Parameter: This method accepts a single parameter as mentioned above and described below:
Return Values: It returns the new i.e. updated year according to universal time which is set by the setUTCFullYear() method.
Note: The DateObj is a valid Date object created using the Date() constructor in which we want to set the year. More codes for the above method are as follows:
Below are examples of the Date setUTCFullYear() method.
Example 1:
Output:
1992
Example 2: If in Date() constructor we do not give any year, still setUTCFullYear() methods will be able to set new year according to universal time which is given as its parameter.
Output:
1992
Example 3: If nothing as a parameter is given in the Date() constructor, still the setUTCFullYear() method will be able to set a year in the created Date object but the month and date remain current ones. Here in output 2 is the month of March because the month name starts from 0 to 11 i.e., 0 for January and 11 for December, and 30 is the current date.
Output:
2007 2 30
We have a complete list of Javascript Date Objects, to check those please go through this article.
Supported Browsers: The browsers supported by the JavaScript Date setUTCFullYear() method are listed below:
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through .