如何在java中添加分钟到日期变量
我有一个带有一些值的日期变量(endTime)(例如:10:40)。 我需要通过向endTime添加10分钟来创建一个新变量。 我该怎么做?
提前致谢
public static String endTime = ""; DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); Calendar cal = Calendar.getInstance(); endTime = timeFormat.format(cal.getTime());`
您可以在Calendar
上使用add
方法:
public static String endTime = ""; DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 10) endTime = timeFormat.format(cal.getTime());`
在Javadoc找到,它需要30秒。