日期:2014-05-20 浏览次数:20754 次
public static List<Date> getSplitTimeList(String startTime, String endTime) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List<Date> dateList = new ArrayList<Date>();
Date startDate = sdf.parse(startTime);
Date endDate = sdf.parse(endTime);
dateList.add(startDate);
dateList.add(endDate);
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.set(Calendar.DAY_OF_MONTH, 20);
Date splitDate1 = null, splitDate2 = null;
while (true) {
splitDate1 = calendar.getTime();
if (splitDate1.after(endDate))
break;
if (!dateList.contains(splitDate1))
dateList.add(splitDate1);
calendar.add(Calendar.DAY_OF_MONTH, 1);
splitDate2 = calendar.getTime();
if (splitDate2.after(endDate))
break;
if (!dateList.contains(splitDate2))
dateList.add(splitDate2);
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 20);
}
if (startDate.getDate() == 20)
dateList.add(startDate);
if (endDate.getDate() == 21)
dateList.add(endDate);
Collections.sort(dateList);
return dateList;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static List<Date> getSplitTimeList(String startTime, String endTime) {