title: Calculate date/time difference in java
body: <p>I want to <strong>calculate difference between 2 dates</strong> in hours/minutes/seconds. </p>
  
  <p>I have a slight problem with my code here it is :</p>
  
  <pre><code>String dateStart = "11/03/14 09:29:58";
  String dateStop = "11/03/14 09:33:43";
  
  // Custom date format
  SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");  
  
  Date d1 = null;
  Date d2 = null;
  try {
      d1 = format.parse(dateStart);
      d2 = format.parse(dateStop);
  } catch (ParseException e) {
      e.printStackTrace();
  }    
  
  // Get msec from each, and subtract.
  long diff = d2.getTime() - d1.getTime();
  long diffSeconds = diff / 1000;         
  long diffMinutes = diff / (60 * 1000);         
  long diffHours = diff / (60 * 60 * 1000);                      
  System.out.println("Time in seconds: " + diffSeconds + " seconds.");         
  System.out.println("Time in minutes: " + diffMinutes + " minutes.");         
  System.out.println("Time in hours: " + diffHours + " hours."); 
  </code></pre>
  
  <p>This should produce :</p>
  
  <pre><code>Time in seconds: 45 seconds.
  Time in minutes: 3 minutes.
  Time in hours: 0 hours.
  </code></pre>
  
  <p>However I get this result :</p>
  
  <pre><code>Time in seconds: 225 seconds.
  Time in minutes: 3 minutes.
  Time in hours: 0 hours.
  </code></pre>
  
  <p>Can anyone see what I'm doing wrong here ?</p>