通过开始时间和结束时间循环获取时间:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date start = format.parse(dataBean.getNewStartDate());//开始时间
Date end = format.parse(dataBean.getNewEndDate());//结束时间
Calendar calendar = Calendar.getInstance();
//calendar.setTime(start);
int dayNum = (int) (end.getTime()-start.getTime())/(24*3600*1000);//开始和结束时间相差天数
List<WorkTaskHoliday> holidayList = new ArrayList<WorkTaskHoliday>();
for(int i=0;i<=dayNum;i++){//批量增加假期信息
WorkTaskHoliday holiday = new WorkTaskHoliday();
calendar.setTime(start);
calendar.add(Calendar.DAY_OF_YEAR, i);//方法获得距离开始时间的第i天
holiday.setHoliday(new Date(calendar.getTimeInMillis()));
}