如何添加20分钟到当前日期? [英] How to add 20 minutes to a current date?

查看:166
本文介绍了如何添加20分钟到当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何添加30分钟到javascript Date对象?

我可以得到这样的当前日期对象:

I can get the current date object like this:

var currentDate = new Date();

如何添加20分钟?

var twentyMinutesLater = ?;


推荐答案

使用 .getMinutes() 获取当前分钟,然后添加20并使用 .setMinutes() 来更新日期对象。

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

这篇关于如何添加20分钟到当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆