导航

获取一段时间内的所有日期

Posted on 2017-08-31 11:06  HerlerTn  阅读(1410)  评论(0)    收藏  举报

public static List Day(String begin, String end) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List strDate = new ArrayList();
strDate.add(begin)
Calendar calendar = Calendar.getInstance();
calendar.setTime(sdf.parse(begin))
boolean bContinue = true;
while (bContinue) {
calendar.add(Calendar.DAY_OF_MONTH, 1)
if (sdf.parse(end).after(calendar.getTime())) {
strDate.add(sdf.format(calendar.getTime()).toString())
} else {
break;
}
}
strDate.add(end)
return strDate
}