junaidp junaidp - 1 year ago 67
Java Question

Java : how to add 10 mins in my Time

I am getting this time

String myTime = "14:10";

Now I want to add like 10 mins to this time, so that it would be

Is this possible, and if so, how?


m0s m0s
Answer Source

Something like this

 String myTime = "14:10";
 SimpleDateFormat df = new SimpleDateFormat("HH:mm");
 Date d = df.parse(myTime); 
 Calendar cal = Calendar.getInstance();
 cal.add(Calendar.MINUTE, 10);
 String newTime = df.format(cal.getTime());

As a fair warning there might be some problems if daylight savings time is involved in this 10 minute period.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download