title: How to convert youtube api v3 duration format to human readable format
body: <p>The output now is: The youtube video Title - PT1H2M11S</p>
  
  <p>How can I convert this duration to a human readable format in seconds using Javascript?</p>
  
  <p>I tried:</p>
  
  <pre><code>$(a).after("&lt;br /&gt;" + b.items[0].snippet.title + " - " + b.items[0].contentDetails.duration..replace("PT","").replace("H",":").replace("M",":").replace("S","") +  "" );
  </code></pre>
  
  <p>But fails when duration is for example: <strong>PT4M9S</strong> then it outputs as <strong>3:9</strong> when it should be <strong>3:09</strong></p>
  
  <pre><code>function checkLink() {
      $("a.link").filter(function () {
          if ($(this).attr("href").match("(http|https)://(www.|m.)?youtube|youtu.be")) {
              youtube_id = $(this).attr("href").match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&amp;\?]*).*/)[2];
              $(this).html('&lt;p style="text-align:center;"&gt;&lt;img src="https://i.ytimg.com/vi/' + youtube_id + '/mqdefault.jpg" /&gt;&lt;/p&gt;');
              var a = $(this).find("img");
              $.ajax({
                  url: "https://www.googleapis.com/youtube/v3/videos?id=" + youtube_id + "&amp;key=**********************&amp;fields=items(snippet(title),contentDetails)&amp;part=snippet,contentDetails",
                  dataType: "json",
                  success: function (b) {
                      $(a).after("&lt;br /&gt;" + b.items[0].snippet.title + " - " + b.items[0].contentDetails.duration +  "" ); 
                  }
              });
              return $(this).attr("href", "https://www.youtube.com/embed/" + youtube_id + "?autoplay=1")
          }
      }).colorbox({
          iframe: !0,
          innerWidth: 640,
          innerHeight: 425
      });
  };
  </code></pre>