How do I subtract minutes from a date in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To subtract minutes to a JavaScript Date object, use the setMinutes() method. JavaScript date setMinutes() method sets the minutes for a specified date according to local time.

Example

You can try to run the following code to subtract 20 minutes.

<html>
   <head>
      <title>JavaScript setMinutes Method</title>
   </head>
   <body>
      <script>
         var dt = new Date("December 31, 2017 11:30:25");
         dt.setMinutes( dt.getMinutes() - 20 );
         document.write( dt );
      </script>
   </body>
</html>
raja
Published on 13-Feb-2018 13:36:24
Advertisements