首页 > 代码库 > 计算一周区间段

计算一周区间段

 private String[] getDateArrByWeek(Date startDate, Date endDate) {  

   Calendar c = Calendar.getInstance();   

    List<String> list = new ArrayList<String>();   

       SimpleDateFormat df = new SimpleDateFormat("YYYY年MM月dd日");   

   for (; startDate.getTime() <= endDate.getTime();) {    

              String _startDate = df.format(startDate);    

              c.setTime(startDate);    

              c.add(Calendar.WEEK_OF_MONTH, 1);    

              startDate = c.getTime();    

              String _endDate = df.format(startDate);    

              c.setTime(startDate);    

              c.add(Calendar.DATE, -1);    

              _endDate = df.format(c.getTime());   

              list.add(_startDate+"-"+_endDate);   

}

             String[] ret = new String[list.size()];   

                   for (int i = 0; i < list.size(); i++) {   

                           ret[i] = list.get(i);   

                  }

  return ret;  }

计算一周区间段