Example 1 — Set the Minutes Only
Change the minutes and keep the existing seconds.
const event = new Date(1975, 7, 19, 23, 15, 30);
event.setMinutes(45);
console.log(event.getMinutes()); // 45
console.log(event.getSeconds()); // 30 How It Works
- Start at 23:15:30. Month index
7is August. - Call
setMinutes(45). Only the minutes argument is provided. - Seconds stay. Because seconds were omitted, they remain
30. - Object mutated. The same
eventnow reads minutes45.

