title: Calculate no of days between two dates in java
body: <p>I need to calculate number of days between two dates and I am using below code. problem is it is returning me 2 but actually it should return 3 because difference between 30 june 2016 to 27 june is 3. can you please help where it should include current date as well in difference?</p>
  
  <pre><code>public static long getNoOfDaysBtwnDates(String expiryDate) {
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      Date expDate = null;
      long diff = 0;
      long noOfDays = 0;
      try {
  
          expDate = formatter.parse(expiryDate);
          //logger.info("Expiry Date is " + expDate);
         // logger.info(formatter.format(expDate));
  
          Date createdDate = new Date();
          diff = expDate.getTime() - createdDate.getTime();
          noOfDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
          long a = TimeUnit.DAYS.toDays(noOfDays);
         // logger.info("No of Day after difference are - " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
          System.out.println(a);
          System.out.println(noOfDays);
  
      } catch (ParseException e) {
          e.printStackTrace();
      }
  
      return noOfDays;
  }
  </code></pre>
  
  <p>expiry date is 2016-06-30 and current date is 2016-06-27</p>