JavaScript Date setMilliseconds() method

The setMilliseconds method in JavaScript is utilized to assign the milliseconds component for a given date, relying on the local time settings.

Syntax

The syntax for the setMilliseconds function is depicted as follows:

Example

dateObj.setMilliseconds( msValue)

Parameter

msValue - This signifies an integer ranging from 0 to 999, denoting the millisecond value. In cases where the supplied millisecond exceeds 999, the setMilliseconds function adjusts the second value accordingly.

JavaScript Date setMilliseconds method example

In this section, we will explore the setMilliseconds method by examining several examples.

Example 1

Let us examine an example that demonstrates how to display both the current and the modified value of seconds.

Example

<script>

var ms=new Date();	

document.writeln("Current millisecond : "+ms.getMilliseconds()+"<br>");

ms.setMilliseconds(825);	

document.writeln("Updated millisecond : "+ms.getMilliseconds());

</script>

Output:

Output

Current millisecond : 750

Updated millisecond : 825

Example 2

Let’s examine an illustration that demonstrates how to modify the second value of the specified time.

Example

<script>

var ms=new Date("August 15, 1947 20:22:110")

ms.setMilliseconds(825);	

document.writeln("Updated millisecond : "+ms.getMilliseconds());

</script>

Output:

Output

Updated millisecond : 825

Input Required

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