JavaScript Date getMilliseconds()
Examples
Get the milliseconds:
const d = new Date();
let ms = d.getMilliseconds();
Try it Yourself »
Get the milliseconds of a specific date:
const d = new Date("July 21, 1983 01:15:00:526");
let ms = d.getMilliseconds();
Try it Yourself »
More examples below.
Definition and Usage
getMilliseconds()
returns the milliseconds (0 to 999) of a date.
Syntax
Date.getMilliseconds()
Parameters
NONE |
Return Value
Type | Description |
A number | The milliseconds of the date (0 to 999). |
Browser Support
getMilliseconds()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
More Examples
Add zeros and colons to display the time:
function addZero(x, n) {
while (x.toString().length < n) {
x = "0" + x;
}
return x;
}
const d = new Date();
let h = addZero(d.getHours(), 2);
let m = addZero(d.getMinutes(), 2);
let s = addZero(d.getSeconds(), 2);
let ms = addZero(d.getMilliseconds(), 3);
let time = h + ":" + m + ":" + s + ":" + ms;
Try it Yourself »