根據時間區間獲取時間區間內所有日期
阿新 • • 發佈:2018-12-21
/** * @param start 開始時間 格式yyyymmdd * @param end 結束時間 格式yyyymmdd * @return list<string>期間的所有日期 */ public static List<String> compeleteDate(String start,String end) { ArrayList<String> aList = new ArrayList<String>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); int num = 0; Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); try { Date date1=sdf.parse(start); Date date2 = sdf.parse(end); c1.setTime(date1); c2.setTime(date2); num = c2.get(Calendar.DAY_OF_YEAR)-c1.get(Calendar.DAY_OF_YEAR); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (num == 0) { return null; } for ( int i = 0 ; i <= num;i++) { aList.add(sdf.format(c1.getTime())); c1.add(Calendar.DAY_OF_YEAR, 1 ); } return aList; }