What is getMilliseconds in JavaScript?

The getMilliseconds function in JS is a method of the Date class. The getMilliseconds function returns the milliseconds part of the Date object it is called on.

Syntax

getMilliseconds()

Parameters

The getMilliseconds function takes no parameters.

Return value

  • An integer from 0 to 999 that represents the milliseconds of the date object.

Example

The following code demonstrates the usage of the getMilliseconds function:

let x = new Date('June 29, 2021 15:39:05:32');
console.log(x.getMilliseconds());

In the example above, the Date object x has the date June 29, 2021 15:39:05:32, where the value in milliseconds is 32. When the function getMilliseconds is called on x, it returns this value.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved