JavaScript setUTCMonth

The JavaScript setUTCMonth function is useful for setting the UTC Month of a specified date according to the Universal Coordinated Time zone.

The syntax of the setUTCMonth function is as follows.

 Date.setUTCMonth(Month_Number, day)

Parameter: The JavaScript setUTCMonth function accepts an integer representing the month. The Month Number should be between 0 and 11. Where 0 = January, and 11 = December.

We can also use the optional day number argument to set the UTC day of the month.

Return Value: It updates the original date with the given month number. If you pass the month number outside the range, the date will roll forward and backward.

JavaScript setUTCMonth example

In this example, we use the setUTCMonth function to set the current date UTC month to 11 (December) according to Coordinated Universal Time.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCMonth(11);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 04:45:14 GMT 
Wed, 16 Dec 2026 04:45:14 GMT

Example 2: In this JavaScript example, we use the Date() constructor to parse a string date and then utilize the setUTCMonth function to set the custom date UTC month to 10 (November) according to Universal Time.

const dt = new Date("May 1, 2025 10:11:19");
console.log(dt.toUTCString());
dt.setUTCMonth(10);
console.log(dt.toUTCString());
Thu, 01 May 2025 04:41:19 GMT 
Sat, 01 Nov 2025 04:41:19 GMT

Example 3: If we use the setUTCMonth function with a month number above 11, the date will roll forward. Here, 25 means (2 years = 24 months) + 1.

The setUTCMonth updates the year value to 2 years ahead and sets the month number to 1, which represents February.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCMonth(25);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 04:48:45 GMT 
Wed, 16 Feb 2028 04:48:45 GMT

Example 4: If the setUTCMonth() function encounters a negative number, it rolls back to the previous year’s last month. For instance, -1 represents December of last year, and -2 means November 2025.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCMonth(-2);
console.log(dt.toUTCString());
Tue, 16 Jun 2026 04:51:56 GMT 
Sun, 16 Nov 2025 04:51:56 GMT

Example 5: In this example, we use the JavaScript setUTCMonth() function to set the UTC month and day of the month numbers. We use the two parameters to set the current date to December 31st.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCMonth(11, 31);
console.log(dt.toUTCString());
console.log(dt.getUTCDate());
console.log(dt.getUTCMonth());
Tue, 16 Jun 2026 04:57:33 GMT 
Thu, 31 Dec 2026 04:57:33 GMT 
31 
11

TIP: Please refer to the getUTCDate() and getUTCMonth() methods to extract the UTC month and day of the month from a date object.

What is the difference between setMonth() and setUTCMonth()?

  • setMonth() sets the given date month and day of the month number according to the local system time zone.
  • setUTCMonth() sets the given date UTC month and day of the month number according to the Universal Coordinated Time zone.

The following example shows the difference between the setMonth() and setUTCMonth() methods.

const dt = new Date();
console.log(dt.toUTCString());
dt.setUTCMonth(10);
console.log(dt.toUTCString());

const d = new Date();
console.log(d);
d.setMonth(10);
console.log(d);
Tue, 16 Jun 2026 05:00:58 GMT 
Mon, 16 Nov 2026 05:00:58 GMT 
Tue Jun 16 2026 10:30:58 GMT+0530 (India Standard Time) 
Mon Nov 16 2026 10:30:58 GMT+0530 (India Standard Time)