JavaScript setMilliseconds

JavaScript setMilliseconds function is a Date Function, which is used to set the Milliseconds of a given date as per local time. The syntax of the setMilliseconds function is:

 Date.setMilliseconds(Milliseconds)

JavaScript setMilliseconds Example

Here, we are using setMilliseconds to set the Milliseconds to 4500000 of the current date.

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  dt.setMilliseconds(4500000);
  document.write("After : " + dt);
</script>
</body>
</html>
Example

Date and Time: Thu Nov 08 2018 12:20:32 GMT+0530 (Indian Standard Time)
After : Thu Nov 08 2018 13:35:32 GMT+0530 (Indian Standard Time)

In this JavaScript set Milliseconds example, we set the Milliseconds of a custom date to 5900000.

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date("January 1, 2017 23:45:22");
  document.write("Date and Time : " + dt + "<br/>");

  dt.setMilliseconds(5900000);
  document.write("After setMilliseconds() : " + dt);
</script>
</body>
</html>
JavaScript setMilliseconds Example