Computer >> Computer tutorials >  >> Programming >> Javascript

How do I subtract minutes from a date in JavaScript?

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.


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

      <title>JavaScript setMinutes Method</title>
         var dt = new Date("December 31, 2017 11:30:25");
         dt.setMinutes( dt.getMinutes() - 20 );
         document.write( dt );