供参考,当前用于制定输出的日期为2015年7月22日,星期三(22/07/2015)
Java 8
LocalDate ld = LocalDate.now();LocalDate sunday = ld.minusDays(ld.getDayOfWeek().getValue());LocalDate tommorrow = ld.plusDays(1);LocalDate date = sunday;while (date.isBefore(tommorrow)) { System.out.println(date); date = date.plusDays(1);}版画
2015-07-192015-07-202015-07-212015-07-22
作为备选
(基本上可以用于所有其他提到的API),您可以从今天开始向后走…
LocalDate date = LocalDate.now();do { System.out.println(date); date = date.minusDays(1);} while (date.getDayOfWeek() != DayOfWeek.SATURDAY);版画
2015-07-222015-07-212015-07-202015-07-19
乔达时间
LocalDate now = LocalDate.now();LocalDate sunday = now.minusDays(5).withDayOfWeek(DateTimeConstants.SUNDAY);LocalDate tommorrow = now.plusDays(1);LocalDate date = sunday;while (date.isBefore(tommorrow)) { System.out.println(date); date = date.plusDays(1);}版画
2015-07-192015-07-202015-07-212015-07-22
日历
不得已。但请记住,
Calendar进行时间信息,因此使用
before,
after并且
equals可能不总是做你认为他们应该…
Calendar cal = Calendar.getInstance();cal.setFirstDayOfWeek(Calendar.SUNDAY);cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);Calendar today = Calendar.getInstance();while (cal.before(today)) { System.out.println(cal.getTime()); cal.add(Calendar.DATE, 1);}版画
Sun Jul 19 15:01:49 EST 2015Mon Jul 20 15:01:49 EST 2015Tue Jul 21 15:01:49 EST 2015Wed Jul 22 15:01:49 EST 2015



