将分钟添加到当前时间,JavaScript

将分钟添加到当前时间,JavaScript,javascript,date,object,Javascript,Date,Object,我想在当前日期的基础上再增加20分钟。在浏览已经发布的关于这个主题的消息时,我恢复了一段代码,但我无法修改它。你能帮我吗 // get the current date & time var dateObj = Date.now(); // I do not understand what these values ​​are dateObj += 1000 * 60 * 60 * 24 * 3; // create a new Date object, using the adju

我想在当前日期的基础上再增加20分钟。在浏览已经发布的关于这个主题的消息时,我恢复了一段代码,但我无法修改它。你能帮我吗

// get the current date & time
var dateObj = Date.now();

// I do not understand what these values ​​are
dateObj += 1000 * 60 * 60 * 24 * 3;

// create a new Date object, using the adjusted time
dateObj = new Date(dateObj);
JavaScript日期对象有一个名为setMinutes的方法

设d=新日期 d、 setMinutesd.getMinutes+20使用这段代码

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

在javascript中处理日期时,我喜欢使用“时刻”:

所以你可以这样做:


矩。加20,‘分钟’

不知道是否定义了值大于60的setMinutes,或者它是意外工作的。您可以这样做:

var current_ms = new Date().getTime();
var in20min = new Date(current_ms + (1000*60*20))

如果您想在不同的地方使用Date对象,请创建一个原型函数,因为它将减少代码的冗余

Date.prototype.add20minutes = function(){
 return this.setMinutes(this.getMinutes() + 20);
}
现在,你只需打电话

var d = new Date();
d.add20minutes(); 
使用此代码:

var date = new Date();
var min = parseInt(date.getMinutes()+20);
date.setMinutes(min);

date.setMinutes?1000*60*60*24*3是以毫秒为单位的三天。我不明白这些值是什么​​一秒钟1000毫秒,一分钟60秒,一小时60分钟,一天24小时,三天。新日期。现在+20*60*1000;date.setMinutesdate.getMinutes+20