0

I have a date variable (endTime) with some value (eg : 10:40). I need to create a new variable by adding 10 minutes to endTime. How can I do it?

Thanks in advance

public static  String endTime = "";
DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
Calendar cal = Calendar.getInstance();

endTime = timeFormat.format(cal.getTime());`
Jonathan
  • 20,053
  • 6
  • 63
  • 70
malik
  • 1
  • 1
  • 3

1 Answers1

6

You can use add method on your Calendar:

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

Found in Javadoc, it takes me 30 seconds.

lpratlong
  • 1,421
  • 9
  • 17
  • 1
    Answering obvious dupes just makes work for people closing duplicates... – Matt Coubrough Jun 04 '14 at 08:35
  • First thing I do when I see a question is to find a solution. I am working and even if I want to help people, I do not have time to look for the specific same solution on SO. – lpratlong Jun 04 '14 at 08:37