JavaScript Date getMilliseconds() method

The getMilliseconds method in JavaScript retrieves the milliseconds component from a given date according to the local time zone.

Syntax

The syntax for the getMilliseconds method is expressed as follows:

Example

dateObj.getMilliseconds()

Return

A numerical value ranging from 0 to 999, which denotes milliseconds within a given date.

JavaScript Date getMilliseconds method example

In this section, we will explore the getMilliseconds method by examining a series of examples.

Example 1

Let's examine an example that demonstrates how to output the current milliseconds.

Example

<script>

var milli =new Date();

document.writeln(milli.getMilliseconds());

</script>

Output:

Example 2

Let us examine an example that demonstrates how to extract and display the value of milliseconds from a specified time.

Example

<script>

var milli =new Date("August 15, 1947 20:22:10:565");

document.writeln(milli.getMilliseconds());

</script>

Output:

Example 3

Let’s explore an example that displays the full current time.

Example

<script>

var milli=new Date();

document.writeln(milli.getHours()+":");

document.writeln(milli.getMinutes()+":");

document.writeln(milli.getSeconds()+":");

document.writeln(milli.getMilliseconds());

</script>

Output:

Output

13: 43: 32: 963

Input Required

This code uses input(). Please provide values below: