momentJS 倒计时返回的日期格式不正确

Incorrect day format returned from momentJS countdown

我使用了来自 https://github.com/icambron/moment-countdown 的这个简单脚本来进行简单的倒计时。我正在使用下面的代码。

Used Code:

$interval(function(){

    $scope.nextDate = moment().countdown($scope.nextDateGet,
        countdown.DAYS|countdown.HOURS|countdown.MINUTES|countdown.SECONDS
    );

    $scope.daysCountdown = moment($scope.nextDate).format('dd');
    $scope.hoursCountdown = moment($scope.nextDate).format('hh');
    $scope.minutesCountdown = moment($scope.nextDate).format('mm');
    $scope.secondsCountdown = moment($scope.nextDate).format('ss');

},1000,0);

This gives correct output

$scope.nextDate.toString();

但这包含一个字符串,其中包含剩余的天数、小时数、分钟数和秒数。所以我决定我想用这个把这个字符串分成 4 个字符串:

$scope.daysCountdown = moment($scope.nextDate).format('dd');
$scope.hoursCountdown = moment($scope.nextDate).format('hh');
$scope.minutesCountdown = moment($scope.nextDate).format('mm');
$scope.secondsCountdown = moment($scope.nextDate).format('ss');

Example for input

2016-10-15 10:00:00 // $scope.nextDateGet

Desired output is something like this:

0 // (days)
12 // (hours)
24 // (minutes)
30 // (seconds)

But i can't seem to format the remainings days, i get this output:

Fr // Shortcode for the day the item is scheduled => I need the remaining days in this case that would be 0. The other formatting is correct.

The following output was correct if remaining days was not 0:

$scope.daysCountdown = moment($scope.nextDate).format('D'); 

If remaining days was 0 it would set remaining days on 14 so this work around did the trick:

if(moment($scope.nextDate).isSame(moment(), 'day')){
    $scope.daysCountdown = 0;
} else {
    $scope.daysCountdown = moment($scope.nextDate).format('D');
}

随时欢迎提出任何改进此代码的建议。