根据开始和结束时间,计算出该时间段每个星期的开始和结束时间

   /***
     * 根据开始和结束时间,计算出该时间段每个星期的开始和结束时间
     * @return 时间段内的开始和结束时间List
     * */
public  List<String> getWeekByTime(String startDate,String endDate){
Calendar c_begin = new GregorianCalendar();
    Calendar c_end = new GregorianCalendar();
    DateFormatSymbols dfs = new DateFormatSymbols();
    List<String> timeList = new ArrayList<String>();
    c_begin.set(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1])-1, Integer.parseInt(startDate.split("-")[2])-1); //Calendar的月从0-11,所以4月是3.
    c_end.set(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1])-1, Integer.parseInt(endDate.split("-")[2])-1); //Calendar的月从0-11,所以5月是4.
    int count = 1;
    c_end.add(Calendar.DAY_OF_YEAR, 1);  //结束日期下滚一天是为了包含最后一天
    int startWeek=0;
  int endWeek=0;
  String startTime="";
  String endTime="";
    while(c_begin.before(c_end)){
    if(count==1){
    if(c_begin.get(Calendar.DAY_OF_WEEK)==1){
    timeList.add(startDate+"&"+new java.sql.Date(c_begin.getTime().getTime())+"");
    }
    }else{
    if(c_begin.get(Calendar.DAY_OF_WEEK)==2){
    startWeek=count;
    startTime=new java.sql.Date(c_begin.getTime().getTime())+"";
    }
     
    if(c_begin.get(Calendar.DAY_OF_WEEK)==1){
    endWeek=count;
    endTime=new java.sql.Date(c_begin.getTime().getTime())+"";
    }
     
    if(startWeek==endWeek){
    timeList.add(startTime+"&"+endTime+"&"+"第"+count+"周 ");
    }
    }
     if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
         count++;
     }
     c_begin.add(Calendar.DAY_OF_YEAR, 1);
    }
    return timeList;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值