问题
I'm working with angularJS and I need to find the next and the previous day of a date.
I have the datepicker
<span data-ng-model="$parent.selected_date" is-open="opened" data-show-button-bar="false" datepicker-popup show-weeks="false" starting-day="1" language="locale" datepicker-options="datepickerConfig" date-disabled="disabled(date, mode)" >
<button type="button" class="btn btn-default btn-md text-center" data-tooltip="{{ 'Interface-UserWeek-Tooltip-Datepicker' | translate }}" data-ng-click="open($event)"> <i class="glyphicon glyphicon-calendar"></i></button>
</span>
I get the data from the ng-model ($parent.selected_date) and I need to get the day after and the day before (it's for implement my date-disabled). I have try to filter :
var day = $filter('date')($scope.$parent.selected_date, 'dd');
day++;
but it doesn't work the way I want when I'm at the end of a month (for example I don't want to find the 32 May but I want to have the 1st of June...)
Thank's
回答1:
The bestest way would be to use moment.js . Bestest time library. click here to use moment.js.
You can simply use
//previous day
moment.subtract('days',1);
//next day
moment.add('days',1);
来源:https://stackoverflow.com/questions/23883272/how-can-i-find-tomorrow-and-yesterday-with-angularjs