`
lxc914_java
  • 浏览: 57493 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

将指定日期段转换为星期,存入到List

阅读更多
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c_begin = new GregorianCalendar();
Calendar c_end = new GregorianCalendar();
DateFormatSymbols dfs = new DateFormatSymbols();
String[] weeks = dfs.getWeekdays();
c_begin.setTime(sdf.parse(form.getStartDate())); //开始日期
c_end.setTime(sdf.parse(form.getEndDate()));     //结束日期
c_end.add(Calendar.DAY_OF_YEAR, 1);  //结束日期下滚一天是为了包含最后一天
List week=new ArrayList();     //存放一周
List weekList=new ArrayList(); //存放所有星期的List
while(c_begin.before(c_end)){
   if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.MONDAY || c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.TUESDAY || c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.WEDNESDAY || c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.THURSDAY || c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.FRIDAY){
        week.add(new java.sql.Date(c_begin.getTime().getTime()));
}
    if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
weekList.add(week);
week=new ArrayList();
}
    c_begin.add(Calendar.DAY_OF_YEAR, 1); //加最后一周
   }
 
}
weekList.add(week);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics