Possible Duplicate:
How to add 30 minutes to a javascript Date object?
I can get the current date object like this:
var currentDate = new Date();
How can I add 20 minutes to it?
var twentyMinutesLater = ?;
To add minutes to a date:Use the getMinutes() method to get the minutes of the specific date. Use the setMinutes() method to set the minutes for the date. The setMinutes method takes the minutes as a parameter and sets the value for the date.
To add hours to a JavaScript Date object, use the setHours() method. Under that, get the current hours and 2 hours to it. JavaScript date setHours() method sets the hours for a specified date according to local time.
const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.
To get current date with Moment and JavaScript, we use the moment function without any arguments. const datetime = moment(); to call moment to get a moment object with the current date.
Use .getMinutes()
to get the current minutes, then add 20 and use .setMinutes()
to update the date object.
var twentyMinutesLater = new Date(); twentyMinutesLater.setMinutes(twentyMinutesLater.getMinutes() + 20);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With