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 = ?;
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 = ?;
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);
new Date(currentDate)
will make a round-trip through a string and drop the milliseconds portion of the date. To clone a date accurately (and more efficiently, not that it's likely to matter), you'd want new Date(+currentDate)
.
Commented
Feb 23, 2016 at 8:21
Add it in milliseconds:
var currentDate = new Date();
var twentyMinutesLater = new Date(currentDate.getTime() + (20 * 60 * 1000));
Just get the millisecond timestamp and add 20 minutes to it:
twentyMinutesLater = new Date(currentDate.getTime() + (20*60*1000))
Just add 20 minutes in milliseconds to your date:
var currentDate = new Date();
currentDate.setTime(currentDate.getTime() + 20*60*1000);
you have a lot of answers in the post
var d1 = new Date (),
d2 = new Date ( d1 );
d2.setMinutes ( d1.getMinutes() + 20 );
alert ( d2 );