How to use setUTCSeconds in JavaScript
In this article, I will explain use of setUTCSeconds() method in JavaScript date object.
JavaScript setUTCSeconds() method
Syntax
Date.setUTCSeconds(sec,milisec)
|
-
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.
Example
In the following example show to setUTCSeconds() method set the seconds and milliseconds.
<!DOCTYPE html>
<html>
<body>
<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();
d.setUTCSeconds(55,990);
var s = d.getUTCSeconds();
var ms = d.getUTCMilliseconds();
var x = document.getElementById("demo");
x.innerHTML ="After set Seconds and milliseconds is : "+s + ":" + ms;
}
</script>
</body>
</html>
|
Output1
Output2
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