Example 1 — Set the UTC Month
Move from January to March while keeping the day.
const date = new Date(Date.UTC(2026, 0, 15)); // Jan 15
date.setUTCMonth(2); // March
console.log(date.getUTCMonth()); // 2
console.log(date.getUTCDate()); // 15
console.log(date.toISOString()); // "2026-03-15T00:00:00.000Z" How It Works
- Build a UTC date.
Date.UTC(2026, 0, 15)is January 15, 2026 UTC (month index0). - Set March.
setUTCMonth(2)uses index2, not3. - Keep the day. Day
15stays because March has at least 15 days. - Confirm ISO. Result is
2026-03-15T00:00:00.000Z.

