How to use setUTCSeconds in JavaScript

In this article, I will explain use of setUTCSeconds() method in JavaScript date object.
  • 1753

JavaScript setUTCSeconds() method

  • setUTCSeconds() method of date object sets the seconds for a specified date according to universal time.
  • setUTCSeconds() method can also be used to set the milliseconds.



  • Sec : Sec is required parameter. An integer is representing the seconds and it's value between 0 and 59.

  • Mili : Mili is optional parameter. A number is representing the milliseconds and it's value between 0 and 999.


In the following example show to setUTCSeconds() method set the seconds and milliseconds.

<!DOCTYPE html>



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

<p id="demo">Click for display seconds and milliseconds after set both of them.</p>

<button onclick="myFunction()">Click On</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();


        var s = d.getUTCSeconds();

        var ms = d.getUTCMilliseconds();

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

        x.innerHTML ="After set Seconds and milliseconds is : "+s + ":" + ms;






UTCSeconds 1.jpg


UTCSeconds 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

© 2020 DotNetHeaven. All rights reserved.