Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add 20 minutes to a current date? [duplicate]

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 = ?; 
like image 230
Richard Knop Avatar asked Dec 23 '10 10:12

Richard Knop


People also ask

How do you add minutes to a Date?

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.

How do you add time to a Date object?

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.

How can I add 1 day to current Date?

const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.

How can I get today's Date in this moment?

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.


1 Answers

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); 
like image 130
Nick Craver Avatar answered Oct 07 '22 21:10

Nick Craver