时间差异以两位数表示

时间:2018-04-19 07:13:17

标签: javascript angularjs datetime

我想以两位数显示TravelTimeHoursDiff和TravelTimeMinutesDiff现在我的时间显示为7:0我希望显示为07:00

 if ($scope.DispatchStatus.ArrivalTime != undefined){
                var today = $rootScope.getSysDate().split(" ");
                var timeArrival = new Date(today[0] + ' ' + $scope.DispatchStatus.ArrivalTime);
                var TravelTime = new Date(today[0] + ' ' + $scope.Route.TravelTime);
                var timeArrivalHours = timeArrival.getHours();
                var TravelTimeHoursDiff = timeArrivalHours - TravelTime.getHours() ;
                var TravelTimeMinutesDiff = (timeArrival.getMinutes() - TravelTime.getMinutes());

                    if(TravelTimeHoursDiff < 0 || (TravelTimeHoursDiff <= 0 && TravelTimeMinutesDiff < 0) || (TravelTimeHoursDiff == 0 && TravelTimeMinutesDiff == 0)){                    
                        $scope.formvalidationbit = $scope.DispatchStatusAddForm[fieldName].$invalid = true;
                         angular.element('#' + fieldName).addClass('ng-invalid');
                         angular.element('#' + fieldName).removeClass('ng-valid');
                         $scope.DispatchStatusAddForm.$valid = false;
                         var errorbit = 1;

                    }else{
                        if (isNaN(TravelTimeHoursDiff)) {
                             TravelTimeHoursDiff = '--';
                         }
                         if (isNaN(TravelTimeMinutesDiff)) {
                             TravelTimeMinutesDiff = '--';
                         }
                         if(TravelTimeMinutesDiff <0){
                             TravelTimeMinutesDiff = TravelTimeMinutesDiff * (-1);
                         }
                         $scope.TravelTime = TravelTimeHoursDiff + ':' + TravelTimeMinutesDiff;
                    }
}

1 个答案:

答案 0 :(得分:1)

只需将前导textbox2.focus(); 添加到小于0的值,例如:

10