java 如何根据当前时间加上几秒钟创建日历对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5177183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:50:51  来源:igfitidea点击:

How to create a calendar object based on current time plus some seconds

java

提问by user496949

I am wondering if I can get a new Calendar object based on current time plus a given timespan, say 5 minutes.

我想知道是否可以根据当前时间加上给定的时间跨度(比如 5 分钟)获得一个新的 Calendar 对象。

回答by Suraj Chandran

Calendar c = Calendar.getInstance(); //gives u calendar with current time
c.add(Calendar.MINUTE, 5); //add 5 minutes to calendar

回答by Sergey Vedernikov

Use addfunction of Calendar class for adding and setTime(new Date())for getting calendar based on current time.

使用Calendar 类的add函数setTime(new Date())根据当前时间添加和获取日历。

回答by Loki

You got to use c.set() methods to set year, month and date for the calendar object.

您必须使用 c.set() 方法来设置日历对象的年、月和日。