How to use setTime in JavaScript

In this article, I will explain use of setTime() method in JavaScript date object.
  • 2113
JavaScript setTime() method
  • setTime() method of date method is used to set the value of a date object to the time represented by a number of milliseconds according to local time.
  • setTime() method is supported in all major browsers.



  • Mili : Mili is required parameter. The number of milliseconds to be added to, or subtracted from, midnight January 1, 1970


In the following example show to how the setTime() method can be used in javascript.

<!DOCTYPE html>



<h3 style="color:Teal ">JavaScript setTime() Method Example</h3>

<p id="demo">Click for display the date after setting the time.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();


        var x = document.getElementById("demo");

        x.innerHTML ="After add 13324038825 millisecond in time : "+ d;






setTime 1.jpg


setTime 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.