58
rated 0 times
[
64]
[
6]
/ answers: 1 / hits: 29135
/ 9 Years ago, mon, march 23, 2015, 12:00:00
What is the best way to convert military time to am and pm time. .
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) ? P.M. : A.M.;
//console.log( timeValue);
}
But I am not satisfied in the output shows when I run my program. .
Sample output:
20:00:00 8:0:0 P.M.
08:00:00 08:0:0 A.M
16:00:00 4:30:0 P.M.
I want to achieve the output which looks like the following:
20:00:00 8:00:00 P.M.
08:00:00 8:00:00 A.M
16:30:00 4:30:00 P.M.
Is there any suggestions there? Thanks
More From » javascript