根据日期时间段获取各个月份

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

  Calendar c = Calendar.getInstance();  

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

 SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月");

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

 String _startDate = df.format(startDate);   

   list.add(_startDate);    

 c.setTime(startDate);    

   c.add(Calendar.MONTH, 1);    //加一个月

   startDate = c.getTime();   

}

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

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

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

}

  return ret;  }

posted @ 2016-12-28 17:21  JLCUI  阅读(940)  评论(0编辑  收藏  举报