Display all days(dates) between two dates in angularjs

随声附和 提交于 2019-12-12 03:26:01

问题


I want to use select "From" and "To" dates from datepicker and display all dates in between, in tabular form using angularjs.


回答1:


Try this function to calculate no. of days. Hope it helps

function daysCalculator(date1, date2) {
  var d1 = new Date(date1);
  var d2 = new Date(date2);
  var days = d1.getTime() - d2.getTime();
  days = parseInt((((days / 1000) / 60) / 60) / 24)
  return days;
}



回答2:


Try using this.

 function getDates(fromDate, toDate) {
        var dateArray = [];
        var nextDate = fromDate;
        while (nextDate <= toDate) {
            dateArray.push( nextDate );
            nextDate.setDate(fromDate.getDate() + 1);
        }
        return dateArray;
    }


来源:https://stackoverflow.com/questions/44624097/display-all-daysdates-between-two-dates-in-angularjs

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