The JavaScript getUTCMilliseconds Date Function returns the Milliseconds from 0 to 999 from a given date according to Universal Coordinated Time (UTC).
The syntax of the getUTCMilliseconds function is:
Date.getUTCMilliseconds()
Return Value: The getUTCSeconds method returns an integer value between 0 and 999 representing the milliseconds from a given date and time.
JavaScript getUTCMilliseconds example
In the following example, we used the getUTCMilliseconds function to return the total milliseconds as per the universal time from the current date and time.
const dt = new Date();
let ms = dt.getUTCMilliseconds();
console.log(ms);
console.log(dt.toISOString());
456
2026-06-13T09:04:32.456Z
Example 2: Using getUTCMilliseconds on a string date
In this JavaScript example, we use the new Date() object to parse a string date. Next, we use the getUTCMilliseconds method to display the Milliseconds from the custom date and time as per Universal Time (UTC).
const dt = new Date("April 10, 2023 10:12:22.0716");
let ms = dt.getUTCMilliseconds();
console.log(ms);
console.log(dt.toISOString());
71
2023-04-10T04:42:22.071Z
Example 3: If we use the JavaScript getUTCMilliseconds() function on a date without a time or milliseconds value, it returns 0. By default, the Date() constructor assigns 0 as the milliseconds value, and the getUTCMilliseconds() method returns that 0 as the output.
const dt = new Date("April 22, 2023 10:12:22");
console.log(dt.getUTCMilliseconds());
console.log(dt.toISOString());
0
2023-04-22T04:42:22.000Z
Example 4: If we pass an invalid date to the getUTCMilliseconds() function, it returns NaN as output. Please refer to the getMilliseconds article.
const dt = new Date("April 32, 2023 10:12:22.0716");
console.log(dt.getUTCMilliseconds());
console.log(dt);
NaN
Invalid Date