title: Calculate Date/Time Difference in Java considering AM/PM
body: <p>I want to calculate the difference between two date/time in java using Date and Calendar classes. The format that I have is "2012-01-24 12:30:00 PM".</p>
  
  <p>I have implemented my own method and also google it to work with others, but haven't getting the right hint to handle AM and PM values.</p>
  
  <p>The date/time difference got troubled whenever the time have 12(AM/PM) in it. For example if I have date/time "2012-01-24 12:30:00 PM" and "2012-01-24 02:30:00 PM" it shows the difference is 10 hours.</p>
  
  <p>Considering the code on <a href="http://technojeeves.com/joomla/index.php/free/71-difference-between-two-dates-in-java" rel="nofollow">this link</a> how can it be modified to handle AM and PM.</p>
  
  <p>To convert String date into Date I use following code:</p>
  
  <pre><code>    String sessionTimeStart = "2012-01-24 12:30:00 PM";
      String sessionTimerEndOrCurrent = "2012-01-24 02:30:00 PM";
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a"); 
  
      Date d1 = null;
      Date d0 = null; 
      try {
          d1 = format.parse(sessionTimeStart);
          d0 = format.parse(sessionTimerEndOrCurrent);
      } catch (ParseException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  </code></pre>