Example 1 — Set the UTC Hour Only
Move the UTC hour to 10 while keeping minutes and seconds.
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45));
date.setUTCHours(10);
console.log(date.getUTCHours()); // 10
console.log(date.getUTCMinutes()); // 30
console.log(date.toISOString()); // "2026-03-01T10:30:45.000Z" How It Works
- Build a UTC date.
Date.UTC(2026, 2, 1, 12, 30, 45)is March 1, 2026 at 12:30:45 UTC (month index2). - Change only the hour.
setUTCHours(10)writes hour10and leaves minutes/seconds alone. - Read it back.
getUTCHours()→10,getUTCMinutes()→30. - Confirm ISO. The trailing
Zmeans UTC —10:30:45.000Z.

