title: How to convert milliseconds to "hh:mm:ss" format?
body: <p>I'm confused. After stumbling upon <a href="https://stackoverflow.com/questions/625433/how-to-convert-milliseconds-to-x-mins-x-seconds-in-java">this</a> thread, I tried to figure out how to format a countdown timer that had the format <code>hh:mm:ss</code>.</p>
  
  <p>Here's my attempt - </p>
  
  <pre><code>//hh:mm:ss
  String.format("%02d:%02d:%02d", 
      TimeUnit.MILLISECONDS.toHours(millis),
      TimeUnit.MILLISECONDS.toMinutes(millis) - 
      TimeUnit.MINUTES.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
      TimeUnit.MILLISECONDS.toSeconds(millis) - 
      TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));   
  </code></pre>
  
  <p>So, when I try a value like <code>3600000ms</code>, I get <code>01:59:00</code>, which is wrong since it should be <code>01:00:00</code>. Obviously there's something wrong with my logic, but at the moment, I cannot see what it is!</p>
  
  <p>Can anyone help?</p>
  
  <p><strong>Edit -</strong></p>
  
  <p>Fixed it. Here's the right way to format milliseconds to <code>hh:mm:ss</code> format -</p>
  
  <pre><code>//hh:mm:ss
  String.format("%02d:%02d:%02d", 
      TimeUnit.MILLISECONDS.toHours(millis),
      TimeUnit.MILLISECONDS.toMinutes(millis) - 
      TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
      TimeUnit.MILLISECONDS.toSeconds(millis) - 
      TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))));
  </code></pre>
  
  <p>The problem was this <code>TimeUnit.MINUTES.toMinutes(TimeUnit.MILLISECONDS.toHours(millis))</code>. It should have been this <code>TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis))</code> instead.</p>