title: Timemillisecond to hh:mm:ss format in java
body: <p>In my code, I am generating timestamps value that is long millisecond .I want to convert this to HH:mm:ss(600000  to 00:10:00),I want disply difference in hh:mm:ss format</p>
  
  <pre><code>String strstart = "8:30:00";
  String strend = "8:40:00";
  
  SimpleDateFormat sdf1 = new SimpleDateFormat("hh:mm:ss");
  try {
      Date date1 = sdf1.parse(strstart);
  
      Date date2 = sdf1.parse(strend);
  
      long durationInMillis = date2.getTime() - date1.getTime();
  
      System.out.println("durationInMillis----&gt;" + durationInMillis);
  
  } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>I use bellow code and the output is <code>0:10:0</code> like this but i want the output like <code>00:10:00</code></p>
  
  <pre><code>int seconds = (int) (durationInMillis / 1000) % 60 ;
  int minutes = (int) ((durationInMillis / (1000*60)) % 60);
  int hours   = (int) ((durationInMillis / (1000*60*60)) % 24);
  
  System.out.println(hours+":"+minutes+":"+seconds);
  </code></pre>