What is the best way to convert wartime to am and pm. I have the following code and it works fine:
$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 >12) ? hours -12 :hours); $scope.timeValue += (minutes < 10) ? ":0" : ":" + minutes; $scope.timeValue += (seconds < 10) ? ":0" : ":" + seconds; $scope.timeValue += (hours >= 12) ? " PM" : " AM"; //console.log( timeValue); }
But I am not satisfied with the output when I run my program.,
Output Example:
20:00:00 8:0:0 PM 08:00:00 08:0:0 AM 16:00:00 4:30:0 PM
I want to get a result that looks like this:
20:00:00 8:00:00 PM 08:00:00 8:00:00 AM 16:30:00 4:30:00 PM
Are there any suggestions? Thanks
source share