title: How to format an elapsed time interval in hh:mm:ss.SSS format in Java?
body: <p>I'm making a stop watch where I'm using Java's SimpleDateFormat to convert the number of milliseconds into a nice "hh:mm:ss:SSS" format. The problem is the hours field always has some random number in it. Here's the code I'm using: </p>
  
  <pre><code>public static String formatTime(long millis) {
      SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss.SSS");
  
      String strDate = sdf.format(millis);
      return strDate;
  }
  </code></pre>
  
  <p>If I take off the hh part then it works fine. Otherwise in the hh part it'll display something random like "07" even if the argument passed in (number of milliseconds) is zero. </p>
  
  <p>I don't know much about the SimpleDateFormat class though. Thanks for any help.</p>