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

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.