获取两个日期之间的所有日期(包涵begin和end)
注释部分:这里是获取两个日期之间的所有日期(不包涵begin和end)
/** * 获取两个日期之间的所有日期(yyyy-MM-dd) * @Description TODO * @param begin * @param end * @return * @author XuJD * @date 2017-4-1 */ private List<Date> getBetweenDates(Date begin, Date end) { List<Date> result = new ArrayList<Date>(); Calendar tempStart = Calendar.getInstance(); tempStart.setTime(begin); /* Calendar tempEnd = Calendar.getInstance(); tempStart.add(Calendar.DAY_OF_YEAR, 1); tempEnd.setTime(end); while (tempStart.before(tempEnd)) { result.add(tempStart.getTime()); tempStart.add(Calendar.DAY_OF_YEAR, 1); }*/ while(begin.getTime()<=end.getTime()){ result.add(tempStart.getTime()); tempStart.add(Calendar.DAY_OF_YEAR, 1); begin = tempStart.getTime(); } return result; }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27