Example 1 — Set the UTC Second Only
Move the UTC second to 10 while keeping milliseconds.
const date = new Date(Date.UTC(2026, 2, 1, 12, 30, 45, 250));
date.setUTCSeconds(10);
console.log(date.getUTCSeconds()); // 10
console.log(date.getUTCMilliseconds()); // 250
console.log(date.toISOString()); // "2026-03-01T12:30:10.250Z" How It Works
- Build a UTC date.
Date.UTC(..., 45, 250)is 12:30:45.250 UTC. - Change only the second.
setUTCSeconds(10)writes second10and leaves ms alone. - Read it back.
getUTCSeconds()→10,getUTCMilliseconds()→250. - Confirm ISO. The trailing
Zmeans UTC —12:30:10.250Z.

