title: Java time datediff using joda
body: <p>This is my code to calculate deference time with joda time:</p>
  
  <pre><code>import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import org.joda.time.Interval;
  import org.joda.time.Period;
  
  public class DateDiff {
  
      public static void main(String[] args) {
  
      DateDiff obj = new DateDiff();
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-DD hh:mm:ss");
  
      try {
  
          Date date1 = simpleDateFormat.parse("2015-10-01 20:32:06");
          Date date2 = simpleDateFormat.parse("2015-10-25 00:52:36");
  
          obj.printDifference(date1, date2);  
  
          } catch (ParseException e) {
          }
      }
  
      public void printDifference(Date startDate, Date endDate){
  
          Interval interval = new Interval(startDate.getTime(), endDate.getTime());
          Period period = interval.toPeriod();
  
          System.out.printf(
              "%d years, %d months, %d days, %d hours, %d minutes, %d seconds%n", 
              period.getYears(), period.getMonths(), period.getDays(),
              period.getHours(), period.getMinutes(), period.getSeconds());
      }
  }
  </code></pre>
  
  <p>Here is my reference : <a href="http://www.mkyong.com/java/java-time-elapsed-in-days-hours-minutes-seconds/" rel="nofollow">http://www.mkyong.com/java/java-time-elapsed-in-days-hours-minutes-seconds/</a>
  When I run the code I received:</p>
  
  <blockquote>
    <p>0 years, 0 months, 2 days, 4 hours, 20 minutes, 30 seconds</p>
  </blockquote>
  
  <p>Can somebody tell me whats wrong with my code?</p>