The JavaScript setUTCFullYear function sets the UTC Year, Month, and Day Number of a specified date according to Coordinated Universal Time.
The syntax of the setUTCFullYear Date function is:
Date.setUTCFullYear(Year_Number, Month, Day_Number)
Parameters: The setUTCFullYear method accepts three parameters. Among them, Month and Day Number are optional arguments.
Return Value: It sets the UTC year, month, and day of the month numbers of a specified date. If we pass the month or day of the month number above the range, the year number will roll forward.
JavaScript setUTCFullYear example
In the following example, we use the setUTCFullYear function to set the current UTC year to 2022 according to the Universal Coordinated Time.
const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCFullYear(2022);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 05:19:08 GMT
Thu, 16 Jun 2022 05:19:08 GMT
Example 2: As mentioned earlier, there are two optional arguments. In this JavaScript setUTCFullYear example, we set the custom date UTC year to 2025, the month to 10 (October), and the day of the month to 15th, according to universal time.
const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCFullYear(2025, 10, 15);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 05:21:15 GMT
Sat, 15 Nov 2025 05:21:15 GMT
Example 3: In this setUTCFullYear example, we use the Date() constructor to parse a custom string date and set the year to 2024, the month to December, and the day to 31st.
const dt = new Date("June 10, 1990 10:22:33");
console.log(dt.toUTCString());
dt.setUTCFullYear(2024, 11, 31);
console.log(dt.toUTCString());
console.log(dt.getUTCFullYear());
console.log(dt.getUTCMonth());
console.log(dt.getUTCDate());
Sun, 10 Jun 1990 04:52:33 GMT
Tue, 31 Dec 2024 04:52:33 GMT
2024
11
31
TIP: Please refer to the getUTCFullYear(), getUTCMonth(), and getUTCDate() methods to extract the UTC year, month, and day of the month.
What is the difference between setFullYear() and setUTCFullYear in JavaScript()?
- setFullYear() sets the year, month, and day of the month number according to the local system time zone.
- setUTCFullYear() sets the UTC year, month, and day of the month number according to the Universal Coordinated Time zone.
const dt = new Date("2026-01-01 01:10:11");
console.log(dt.toUTCString());
dt.setUTCFullYear(2023);
console.log(dt.toUTCString());
const d = new Date("2026-01-01 01:10:11");
console.log(d.toString());
d.setFullYear(2023);
console.log(d.toString());
Wed, 31 Dec 2025 19:40:11 GMT
Sun, 31 Dec 2023 19:40:11 GMT
Thu Jan 01 2026 01:10:11 GMT+0530 (India Standard Time)
Sun Jan 01 2023 01:10:11 GMT+0530 (India Standard Time)
NOTE: If we replace d.setFullYear(2023) with d.setUTCFullYear(2023), the result becomes January 2024 because of the time zone difference.
What if the setUTCFullYear month and day parameter exceeded the range?
In the JavaScript setUTCFullYear function, if we use a month number greater than 11 or a day number above 31, the date will roll forward. In the example below, we use the setUTCFullYear method with 2024, 14, and 35 as parameters.
- 2024 sets the current year to 2024.
- 14 = (12 months as one year and set the month number to 2). So, the year became 2025 and the month was March (2).
- 35 = March has 31 days + extra 4 days. So, the month becomes April and the day of the month becomes 4.
const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCFullYear(2024, 14, 35);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 05:36:49 GMT
Fri, 04 Apr 2025 05:36:49 GMT