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.

Syntax

Date.setTime(milisec)

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

Example

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

<!DOCTYPE html>

<html>

<body>

<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();

        d.setTime(13324038825);

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

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

    }

</script>

</body>

</html>

Output1

setTime 1.jpg

Output2

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.