title: Java 8 calculate months between two dates
body: <p><strong>NOTE THIS IS NOT A DUPLICATE OF EITHER OF THE FOLLOWING</strong></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1555262/calculating-the-difference-between-two-java-date-instances">Calculating the difference between two Java date instances</a> </li>
  <li><a href="https://stackoverflow.com/questions/18440083/calculate-months-between-two-dates-in-java">calculate months between two dates in java [duplicate]</a></li>
  </ul>
  
  <hr/>
  
  <p>I have two dates:</p>
  
  <ul>
  <li>Start date: <code>"2016-08-31"</code> </li>
  <li>End date: <code>"2016-11-30"</code></li>
  </ul>
  
  <p>Its 91 days duration between the above two dates, I expected my code to return 3 months duration, but the below methods only returned 2 months. Does anyone have a better suggestion? Or do you guys think this is a bug in Java 8?  91 days the duration only return 2 months.</p>
  
  <p>Thank you very much for the help.</p>
  
  <p>Method 1:</p>
  
  <pre><code>Period diff = Period.between(LocalDate.parse("2016-08-31"),
      LocalDate.parse("2016-11-30"));
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>long daysBetween = ChronoUnit.MONTHS.between(LocalDate.parse("2016-08-31"),
      LocalDate.parse("2016-11-30"));
  </code></pre>
  
  <p>Method 3:</p>
  
  <p>I tried to use Joda library instead of Java 8 APIs, it works. it loos will return 3, It looks like Java duration months calculation also used days value. But in my case, i cannot use the Joda at my project. So still looking for other solutions.</p>
  
  <pre><code>    LocalDate dateBefore= LocalDate.parse("2016-08-31");
      LocalDate dateAfter = LocalDate.parse("2016-11-30");
      int months = Months.monthsBetween(dateBefore, dateAfter).getMonths();
      System.out.println(months);
  </code></pre>