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

+5

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

#-_Scripter_-#

6 Answers

New Answer

+4

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 👍

+8

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

+6

Use moment.js in React https://code.sololearn.com/W4x618SP3RZT/?ref=app

+5

Use moment.js subtract method https://code.sololearn.com/W8S5M4mSTK57/?ref=app

+2

If there is a solution through jquery, then also write

+1

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(… ) https://code.sololearn.com/WkgNUX74q7Tu/?ref=app