Example 1 — Set the Milliseconds
Write a value in the normal 0–999 range.
const event = new Date(1975, 7, 19, 23, 15, 30);
console.log(event.getMilliseconds()); // 0
event.setMilliseconds(456);
console.log(event.getMilliseconds()); // 456 How It Works
- Start at 23:15:30. Constructor defaults milliseconds to
0. - Read first.
getMilliseconds()confirms0. - Write
456.setMilliseconds(456)updates only the fraction. - Read again.
getMilliseconds()now returns456.

