Example 1 — Set UTC Milliseconds
Change only the .mmm part of a UTC timestamp.
const date = new Date("2018-01-24T12:38:29.069Z");
console.log(date.getUTCMilliseconds()); // 69
date.setUTCMilliseconds(420);
console.log(date.getUTCMilliseconds()); // 420
console.log(date.toISOString()); // "2018-01-24T12:38:29.420Z" How It Works
- Parse a UTC ISO string. The date starts at
.069milliseconds. - Read the fraction.
getUTCMilliseconds()returns69. - Write a new value.
setUTCMilliseconds(420)replaces only the ms field. - Confirm ISO. Hours/minutes/seconds stay the same; the string ends in
.420Z.

