开发者

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

This question already has answers here: Closed 12 years ago. 开发者_JAVA技巧

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);


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);


var d = new Date();
var v = new Date();
v.setMinutes(d.getMinutes()+20);


you have a lot of answers in the post

var d1 = new Date (),
d2 = new Date ( d1 );
d2.setMinutes ( d1.getMinutes() + 20 );
alert ( d2 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜