how can i find tomorrow and yesterday with angularjs

只谈情不闲聊 提交于 2020-01-05 04:37:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!