Method
JavaScript Date getMilliseconds() Method
The getMilliseconds() method in JavaScript is used to get the milliseconds (from 0 to 999) of the specified date and time, according to local time.
Syntax
The syntax of the getMilliseconds() method is given below:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
dateObj.getMilliseconds()
[/dm_code_snippet]
Here, dateObj is the Date object.
Return Value
The getMilliseconds() method returns the milliseconds (from 0 to 999) of the specified date and time, according to local time.
JavaScript getMilliseconds() Example 1:
In this example, we will create a Date object using the new Date() constructor and get the milliseconds of the Date object using the getMilliseconds() method.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
var d = new Date(); var n = d.getMilliseconds(); document.write(n);
[/dm_code_snippet]
Output:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
743
[/dm_code_snippet]
JavaScript getMilliseconds() Example 2:
In this example, we will create a Date object using the new Date(milliseconds) constructor and get the milliseconds of the Date object using the getMilliseconds() method.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
var d = new Date(1577393545455); var n = d.getMilliseconds(); document.write(n);
[/dm_code_snippet]
Output:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
455
[/dm_code_snippet]