title: Convert seconds to minutes and seconds in MM:SS format
body: <p>I want to convert seconds to minutes and seconds in the format MM:SS . The below code is working fine but converting seconds to M:SS format. How can I change it to MM:SS format.</p>
  <p>For example, when passing <code>150 seconds</code> to <code>format(150)</code> giving <code>2:30</code> but i need it like <code>02:30</code></p>
  <pre><code> function format(time) {   
          // Hours, minutes and seconds
          var hrs = ~~(time / 3600);
          var mins = ~~((time % 3600) / 60);
          var secs = ~~time % 60;
      
          // Output like &quot;1:01&quot; or &quot;4:03:59&quot; or &quot;123:03:59&quot;
          var ret = &quot;&quot;;
          if (hrs &gt; 0) {
              ret += &quot;&quot; + hrs + &quot;:&quot; + (mins &lt; 10 ? &quot;0&quot; : &quot;&quot;);
          }
          ret += &quot;&quot; + mins + &quot;:&quot; + (secs &lt; 10 ? &quot;0&quot; : &quot;&quot;);
          ret += &quot;&quot; + secs;
          return ret;
      }
  </code></pre>