How to subtract minutes from minutes in javascript? | Sololearn: Learn to code for FREE!


How to subtract minutes from minutes in javascript?

For example, I need to subtract 20 minus 30 minutes, but when subtracting it turns out minus 10, please help

7/22/2021 1:12:47 AM


6 Answers

New Answer


Get the value from `Date` object in milliseconds into a variable e.g. <ms> by using valueOf() method. Then you subtract <ms> by number of milliseconds in 30 minutes. Note that there are 60000 milliseconds in a minute, so you multiply that by 30 (minutes). Finally, create a new `Date` object from <ms>. I think it will work, give it a try 👍


Can you show your code? That helps people figure out what went wrong.


Use moment.js in React


Use moment.js subtract method


If there is a solution through jquery, then also write


This program will calculate the time elapsed in minutes and seconds from the last call to mainLoop(). notice the use of the Absolute function from the Math module. thats infact what you need.. Math. abs(… )