JAVA中返回两个时间段内所有的日期

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

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

		try {
			Date dateOne = sdf.parse(dateStart);
			Date dateTwo = sdf.parse(dateEnd);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(dateOne);

			dateList.add(sdf.format(dateOne));
			while (calendar.getTime().before(dateTwo)) {
				calendar.add(Calendar.DAY_OF_MONTH, +1);
				dateList.add(sdf.format(calendar.getTime()));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
       for (String day : dateList) {
			System.out.println(day);
		}

你可能感兴趣的:(java)