title: How to calculate time difference between two dates using LocalDateTime in Java 8?
body: <p>There are numerous answers given but I am unable to find compatible with my situation. I need to find difference of 8 hours in time as well as on date change too. Like if time is greater then 8 hours then do not execute something .</p>
  
  <p>Do we have any method which achieve the same in <code>LocalDateTime</code> in Java-8?</p>
  
  <p>I have tried to use following but unable to achieve the same.</p>
  
  <pre><code>LocalDateTime fromDateTime = LocalDateTime.of(2017, 07, 07, 07, 00, 55);
  LocalDateTime toDateTime = LocalDateTime.now();
  LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
  
  long years = tempDateTime.until(toDateTime, ChronoUnit.YEARS);
  tempDateTime = tempDateTime.plusYears(years);
  
  long months = tempDateTime.until(toDateTime, ChronoUnit.MONTHS);
  tempDateTime = tempDateTime.plusMonths(months);
  
  long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
  tempDateTime = tempDateTime.plusDays(days);
  
  long hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
  tempDateTime = tempDateTime.plusHours(hours);
  
  long minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
  tempDateTime = tempDateTime.plusMinutes(minutes);
  
  long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
  
  System.out.println("" + java.time.Duration.between(tempDateTime, toDateTime).toHours());
  
  System.out.println(years + " years "
          + months + " months "
          + days + " days "
          + hours + " hours "
          + minutes + " minutes "
          + seconds + " seconds.");
  </code></pre>
  
  <p>It is difficult to check on time and date separately.</p>
  
  <p>Initially I coded it like but it does not looks correct:</p>
  
  <pre><code>return openBrat!=null 
          &amp;&amp; openBrat.until(LocalDateTime.now(), ChronoUnit.DAYS) == 0 &amp;&amp;  
            openBrat.until(LocalDateTime.now(), ChronoUnit.HOURS) &gt;= 8
           &amp;&amp; openBrat.until(LocalDateTime.now(), ChronoUnit.Minutes) &gt;= 0;
  </code></pre>
  
  <p>Could anyone please suggest how to subtract like:</p>
  
  <pre><code>2017 07 06 23:30:00 - 2017 07 07 01:30:00 - Should return 2 hours.
  </code></pre>