Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Calculate the time in the middle of two hours

1. ## Calculate the time in the middle of two hours

How to calculate if today is 22:40:30 and tomorrow is 05:10:45, what hour and minute and second between these two times? That is, exactly what time it is?

2. ## Re: Calculate the time in the middle of two hours

Its all arithmetic. There are 24 hours in a day, 60 minutes in an hour and 60 seconds in a minute.
Work in seconds. Get difference, divide by 2, add to first date and convert to H:M:S for results.

3. ## The Following User Says Thank You to Norm For This Useful Post:

cnmeysam (March 29th, 2021)

4. ## Re: Calculate the time in the middle of two hours

It means

```
prayerTimes.get(0) = 05:10:45
prayerTimes.get(4) = 22:40:30

String t3 = prayerTimes.get(0);
String t4 = prayerTimes.get(4);

System.out.println(t3 + "--" + t4);
System.out.println(Duration.between(
LocalTime.parse(t4),
LocalTime.parse(t3)
).plusNanos(1).withNanos(0));```
after that i don't now how i must find time

5. ## Re: Calculate the time in the middle of two hours

Work on the logical steps required to solve the problem BEFORE writing any code.
Can you make a list of the steps required?

There may be some ideas here: https://www.baeldung.com/java-date-difference

6. ## The Following User Says Thank You to Norm For This Useful Post:

cnmeysam (March 29th, 2021)