How to add 10 seconds to a JavaScript date object?

JavascriptWeb DevelopmentFront End Technology

To add seconds to a JavaScript Date object, use the setSeconds() method. Under that, get the current seconds and add 10 seconds to it. JavaScript date setSeconds() method sets the seconds for a specified date according to local time.

You can try to run the following code to add 10 seconds to date.

Example

 Live Demo

<html>
   <head>
      <title>JavaScript setSeconds Method</title>
   </head>
   <body>
      <script>
         var dt = new Date("December 30, 2017 11:20:25");
         dt.setSeconds( dt.getSeconds() + 10 );
         document.write( dt );
      </script>
   </body>
</html>

Output

Sat Dec 30 2017 11:20:35 GMT+0530 (India Standard Time)
raja
Published on 13-Feb-2018 08:36:22
Advertisements