.setUTCFullYear()
The .setUTCFullYear()
method of Date
instances changes the year for the date according to UTC (Coordinated Universal Time).
Syntax
myDate.setUTCFullYear(yearValue)
myDate.setUTCFullYear(yearValue, monthValue)
myDate.setUTCFullYear(yearValue, monthValue, dateValue)
Parameters:
yearValue
: An integer representing the year. For example, 1995.monthValue
: (Optional) An integer representing the month: 0 for January, 1 for February, and so on.dateValue
: (Optional) An integer between 1 and 31 representing the day of the month. IfdateValue
is specified,monthValue
must also be specified.
The method changes the Date
object in place, and returns its new timestamp. If a parameter is NaN
(or other values that get coerced to NaN
, such as undefined
), the date is set to Invalid Date
and NaN
is returned.
If the monthValue
and dateValue
parameters are not specified, the values returned from the .getUTCMonth()
and .getUTCDate()
methods are used.
Note: If a parameter specified is outside of the expected range,
.setUTCFullYear()
attempts to update the other parameters and the date information in theDate
object accordingly. For example, if 15 is specified formonthValue
, the year is incremented by 1 (yearValue + 1
), and 3 is used for the month.
Example
Using .setUTCFullYear()
:
const theBigDay = new Date('2023-03-01');theBigDay.setUTCFullYear(1997);console.log(theBigDay);
This code will output the following:
1997-03-01T00:00:00.000Z
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours