JavaScript date.getMilliseconds() method
The date.getMilliseconds()
method in JavaScript returns the milliseconds (from 0 to 999) of a specific Date
object, according to local time.
Syntax:
Returns:
- A number between 0 and 999 that represents the milliseconds of the specified date.
Example 1: Getting Milliseconds for a Specific Date and Time
Output:
Explanation:
- The
Date
object represents October 22, 2024, at 15:30:45.123 (3:30:45 PM and 123 milliseconds). ThegetMilliseconds()
method returns123
.
Example 2: Getting Milliseconds for Midnight
Output:
Explanation:
- At midnight (00:00:00.000), there are no milliseconds, so
getMilliseconds()
returns0
.
Example 3: Getting Current Milliseconds
Output:
Explanation:
- This retrieves the current milliseconds of the time according to the user's local time. For example, if the current time is 11:30:45.567, the output will be
567
.
Summary:
date.getMilliseconds()
returns the milliseconds component of aDate
object, ranging from 0 to 999.- This method is useful for extracting the precise timing information of a date and time object, especially in scenarios involving high-resolution timing.