## Problem Description :

Write a program in Java that adds two times that are given in format HH:mm:ss with proper validations. For example - addition of 11:12:45 and 23:45:44 is 1:10:58:29 or 1 Day 10 Hours 58 Minutes 29 Seconds.

## Concept :

The algorithm that we are using for solving this problem is very simple and straight forward.

• Split both given strings by delimiter ":".
• Now we have to convert hours, minutes and seconds to Integer.
• Do an addition of hours, minutes and seconds. If the value of hours>23, add 1 to days because 1 day=24 hours, if the value of minutes > 59, add 1 hour to hours because 1 hour=60 minutes and if the value of seconds > 59, add 1 minute to minutes because 1 minute=60 seconds.
• Convert hours, minutes and seconds into String and combine using ":".

## Output :

 Output - How to add two given times in Java?

## References :

Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.

Tags : Date and Time problems, Time addition in Java, Solution in Java, String, if else statement, Regular expressions.

I am simple guy with lot of ambitions. My main motive is to share whatever knowledge I have related to programming. With me you can easily learn how to solve any programming problem in Java.You can connect with me on social networking sites also.

How to add two given times in HH:mm:ss format in Java? Reviewed by Rohit Agarwal on 1/15/2017 Rating: 5