title: Java - Time difference in minutes
body: <p>I have this problem with calculating time difference in minutes.
  Its working fine with exampples like calculating the difference between
  2045 and 2300.</p>
  
  <p>But when I want to calculate the difference between for example
  2330 (today) and 0245 (tomorrow) I get a incorrect answer.
  Code below:</p>
  
  <pre><code>    // This example works
      String dateStart = "2045";
      String dateStop = "2300";
  
      // This example doesnt work
      //String dateStart = "2330";
      //String dateStop = "0245";
  
      // Custom date format
      SimpleDateFormat format = new SimpleDateFormat("HHmm");  
  
      Date d1 = null;
      Date d2 = null;
      try {
          d1 = format.parse(dateStart);
          d2 = format.parse(dateStop);
      } catch (Exception e) {
          e.printStackTrace();
      }    
  
      long diff = d2.getTime() - d1.getTime();
      long minutes = TimeUnit.MILLISECONDS.toMinutes(diff);                      
      System.out.println("Time in minutes: " + minutes + " minutes.");
  </code></pre>
  
  <p>Thanks in advance</p>