'JS how to add hours and minutes to scheduled date
I need to be able to let clients schedule a certain type of meeting for a future date, the meeting duration I get back from the database is in minutes. I need to be able to create a future start date and time, then add the duration minutes to that time and get the end date and time. Then convert those two to utc time and iso format to send to backend. I know how to convert to utc and iso, just not sure of the best way to add times with the duration being in minutes. Any one know the best way to do this with javascripts date api, moment.js or another library?
Solution 1:[1]
I like to approach problems with time using the date-fns library. Today the Date object solves "most" of our problems so date-fns helps giving useful functions to manipulate dates.
What you might be looking for is the add minutes function. Also the formatISO might help.
For UTC, the UTC method should work fine.
Solution 2:[2]
With the Date API, you can:
// hours
date.setHours(date.getHours() + someHours);
// minutes
date.setMinutes(date.getMinutes() + someMinutes);
// whatever else...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | lmonninger |