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 JavaScript setMilliseconds function is:

 Date.setMilliseconds(Milliseconds)

JavaScript setMilliseconds Function Example

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

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

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

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

JavaScript set Milliseconds Function Example 2

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

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Set Milliseconds Functions </title>
</head>
<body>
    <h1> JavaScript setMilliseconds Function 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 Function 2