try {
List timelist = DateUtils.getDateListBySETime("2015-08-01", "2015-11-30");
if(timelist!=null&&timelist.size()>0){
int SIZE = 10;
int page = (timelist.size() + SIZE - 1)/SIZE;
List newtimelist=null;
for(int i = 0;i < page;i++) {
newtimelist=new ArrayList();
if(i==page-1){
newtimelist=timelist.subList(i*SIZE, timelist.size());
}else {
newtimelist=timelist.subList(i*SIZE, i*SIZE+SIZE);
}
//markToDBLineByDate(timelist.get(0),timelist.get(timelist.size()-1),"1");
System.out.println("~~~时间:"+newtimelist.get(0)+"~~~~~~~结束时间:"+newtimelist.get(newtimelist.size()-1));
}
}
} catch (Exception e) {
e.printStackTrace();
}
/**
* 根据开始时间和结束时间把时间集合输出
* @param startTime
* @param endTime
* @return
* @throws Exception
*/
public static List getDateListBySETime(String startTime, String endTime) throws Exception {
if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){
//格式转换
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
//开始日期
Date sDate = sf.parse(startTime);
//结束日期
Date eDate = sf.parse(endTime);
List list = new ArrayList();
//首先加入第一项
list.add(startTime);
//当开始时间小于等于结束时间的时候
while(sDate.getTime()
//开始时间+1天
Calendar sc = Calendar.getInstance();
sc.setTime(sDate);
sc.add(sc.DAY_OF_MONTH,+1);
//赋给开始时间
sDate = sc.getTime();
//赋给集合
list.add(sf.format(sDate));
}
return list;
}
return null;
}
原文:http://www.cnblogs.com/dreamzhiya/p/5040157.html