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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Calculate the time in the middle of two hours

  1. #1

    Default Calculate the time in the middle of two hours

    hi thanks for your help
    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?
    Last edited by cnmeysam; March 29th, 2021 at 03:08 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    cnmeysam (March 29th, 2021)

  4. #3

    Default 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
    Last edited by cnmeysam; March 25th, 2021 at 06:06 PM.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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
    If you don't understand my answer, don't ignore it, ask a question.

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

    cnmeysam (March 29th, 2021)

Similar Threads

  1. Trying to calculate hours by the hour
    By mattig89ch in forum Object Oriented Programming
    Replies: 4
    Last Post: January 5th, 2018, 09:19 PM
  2. daily time record & computation of hours work
    By cess in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 14th, 2014, 02:42 AM
  3. Re: Willing to volunteer 10 hours per week of programming time
    By fru1tfly in forum Java Theory & Questions
    Replies: 1
    Last Post: September 3rd, 2012, 02:24 PM
  4. Willing to volunteer 10 hours per week of programming time
    By Otiose Dodge in forum Paid Java Projects
    Replies: 6
    Last Post: August 27th, 2012, 01:09 PM
  5. Removing the middle cell
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 7th, 2010, 01:35 PM

Tags for this Thread