How to subtract minutes from date in JavaScript
To subtract minutes from date in JavaScript you just need to use setMinutes() and getMinutes() methods. Here we will see how easily we can subtract minutes from a date in JS with an example.
These below tutorials are very closely related and similar to this one, you can also read,
- How to add months to a date in JavaScript
- Add minutes to date in JavaScript date object
- Subtract days from a date in javascript
How to Subtract minutes from date in JavaScript
Here we will subtract 10 minutes from a date in JavaScript, take a look
<!DOCTYPE html> <html> <head> <title>Title Goes Here</title> </head> <body> <script type="text/javascript"> var date1 = new Date(); date1.setMinutes(date1.getMinutes()-10); document.write(date1); </script> </body> </html>
Output: Thu Nov 11 2018 10:24:03 GMT+0530 (India Standard Time)
My current system time was 10:34:03
So you have seen how to do this.
If you want to know more about
getMinutes() and setMinutes() method please go through the following tutorial and read the last portion of that
getMinutes() setMinutes() in JS
Also read,
Leave a Reply