JavaScript > Date

SetMilliseconds() Method in JavaScript

How to set the milliseconds of a date object in JavaScript?

By using setMilliseconds() method we can set the milliseconds of a date object.

<p>Click the below button to set the Milliseconds of a date object.</p>
<input type="button" value="Click" onclick="myDate()" />
<p id="myId"></p>

    function myDate() {
        var a = new Date();
        var r = a.getMilliseconds();
        document.getElementById("myId").innerHTML = r;

In the above code snippet we have given Id as "myId"to the second <p> element in the HTML code. There is a function myDate() in the<script>block which is connected to the Onclick of the HTML button. The document.getElementById("myId")returns the element that has Id"id=myID" in the HTML page. We need to set the milliseconds of a date object, for that we are using setMilliseconds() method. In the code setMilliseconds() method sets the milliseconds of date object and getMilliseconds() method return the entered milliseconds as output. Onclick of the button "Click" in HTML code fires thye function myDate() in the <script> block, at the same time setMilliseconds() sets the milliseconds of a date object 


 Views: 622 | Post Order: 120

Write for us