title: Best way to convert military time to standard time in javascript
body: <p>What is the best way to convert military time to am and pm time. .
  I have the following code and it works fine:</p>
  
  <pre><code>$scope.convertTimeAMPM = function(time){
  //var time = "12:23:39";
  var time = time.split(':');
  var hours = time[0];
  var minutes = time[1];
  var seconds = time[2];
  $scope.timeValue = "" + ((hours &gt;12) ? hours -12 :hours);
      $scope.timeValue += (minutes &lt; 10) ? ":0" : ":" + minutes;
      $scope.timeValue += (seconds &lt; 10) ? ":0" : ":" + seconds;
      $scope.timeValue += (hours &gt;= 12) ? " P.M." : " A.M.";
      //console.log( timeValue);
  }
  </code></pre>
  
  <p>But I am not satisfied in the output shows when I run my program. . </p>
  
  <p>Sample output:</p>
  
  <pre><code>20:00:00   8:0:0 P.M.
  08:00:00   08:0:0 A.M
  16:00:00   4:30:0 P.M.
  </code></pre>
  
  <p>I want to achieve the output which looks like the following:</p>
  
  <pre><code>20:00:00   8:00:00 P.M.
  08:00:00   8:00:00 A.M
  16:30:00   4:30:00 P.M.
  </code></pre>
  
  <p>Is there any suggestions there? Thanks</p>