Home >>JavaScript Date Object Methods >JavaScript setSeconds() Method
JavaScript setSeconds() method is an inbuilt method in JavaScript which is used to set the seconds of a date object with a valid second value between 0-59 on the basis of local time.
Syntax:Date.setSeconds(sec, millisec)
Parameter | Description |
---|---|
sec | It is Required and represents an integer value between 0 and 59 (specifying the seconds). This method increments the minutes value, if the provided seconds value is greater than 59. |
millisec | It is Optional and represents an integer value between 0 and 999 (specifying the milliseconds). This method increments the seconds value, if the provided milliseconds value is greater than 999. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
setSeconds() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <button onclick="mySetSec()">click me</button> <p id="sec1"></p> <script> function mySetSec() { var d = new Date(); d.setSeconds(55); document.getElementById("sec1").innerHTML = d; } </script> </body> </html>
<html> <body> <script> var sec2=new Date(); document.writeln("Current Second : "+sec2.getSeconds()+"<br>"); sec2.setSeconds(35); document.writeln("Updated Second : "+sec2.getSeconds()); </script> </body> </html>