JavaScript setUTCMilliseconds

The JavaScript setUTCMilliseconds function is useful for setting the Milliseconds of a specified date according to the universal time (UTC).

The syntax of the setUTCMilliseconds method is:

 Date.setUTCMilliseconds(Milliseconds)

Parameters: The JavaScript setUTCMilliseconds method accepts the milliseconds to set or update the existing milliseconds of a given date and time.

Return Value: It updates the existing date’s millisecond value with the user-given value. If we pass a value above 999, it updates the seconds value, and then the remaining number is assigned to milliseconds.

JavaScript setUTCMilliseconds example

In the example, we use the setUTCMilliseconds function to set the current date Milliseconds to 300 as per the Universal Coordinated Time zone.

const dt = new Date();
console.log(dt.toISOString());
dt.setUTCMilliseconds(300);
console.log(dt.toISOString());
2026-06-15T12:59:47.906Z 
2026-06-15T12:59:47.300Z

Example 2: If we pass a milliseconds (parameter) value greater than 999, the date will roll forward to the next. For instance, if we set the milliseconds to 1500, the setUTCMilliseconds method will update seconds by 1 (1000 ms), and the remaining 500 is set as milliseconds.

const dt = new Date();
console.log(dt.toISOString());
dt.setUTCMilliseconds(1500);
console.log(dt.toISOString());
2026-06-15T13:01:46.799Z 
2026-06-15T13:01:47.500Z

In the following example, we set the UTC milliseconds to 500000. It converts 500000 to hours, minutes, and seconds and updates those values.

const dt = new Date();
console.log(dt.toISOString());
dt.setUTCMilliseconds(500000);
console.log(dt.toISOString());
2026-06-15T13:03:11.589Z 
2026-06-15T13:11:31.000Z

Example 3: In this JavaScript setUTCMilliseconds example, we set the custom date Milliseconds to 100000 according to universal time.

const dt = new Date("May 1, 2016 10:11:19.111");
console.log(dt.toISOString());
dt.setUTCMilliseconds(100000);
console.log(dt.toISOString());
2016-05-01T04:41:19.111Z 
2016-05-01T04:42:59.000Z

Example 4: If we use setUTCMilliseconds with negtive milliseond value, the date will roll back to the previous seconds.

const dt = new Date();
console.log(dt.toISOString());
dt.setUTCMilliseconds(-500);
console.log(dt.toISOString());
2026-06-15T13:07:03.906Z 
2026-06-15T13:07:02.500Z

TIP: Use the getUTCMilliseconds method to get the UTC milliseconds value.

Difference between setMilliseconds and setUTCMilliseconds?

As there is no milliseconds difference between UTC zone and the local system time zone, both setMilliseconds and setUTCMilliseconds return the same result.