什么是将军时间转换为上午和下午时间的最佳方法。我有以下代码,它运行良好:
我希望实现以下类似的输出:
```html
$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);
}
但是当我运行程序时,输出结果并没有让我满意。
样例输出:
20:00:00 8:0:0 P.M.
08:00:00 08:0:0 A.M
16:00:00 4:30:0 P.M.
我希望实现以下类似的输出:
```html
我想要达到以下输出结果:
```20:00:00 8:00:00 P.M.
08:00:00 8:00:00 A.M
16:30:00 4:30:00 P.M.
那里是否有任何建议?谢谢