使用出色的http://www.joda.org/joda-time/库,这是一种更简单的方法:
String start = "01/01/2009";String end = "12/09/2013";DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/MM/yyyy");DateTime startDate = pattern.parseDateTime(start);DateTime endDate = pattern.parseDateTime(end);List<DateTime> fridays = new ArrayList<>();while (startDate.isBefore(endDate)){ if ( startDate.getDayOfWeek() == DateTimeConstants.FRIDAY ){ fridays.add(startDate); } startDate = startDate.plusDays(1);}最后,您将在星期五数组中包含星期五。简单?
或者,如果您想加快进度,在遇到星期五后,可以从使用几天切换到使用几周:
String start = "01/01/2009";String end = "12/09/2013";DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/MM/yyyy");DateTime startDate = pattern.parseDateTime(start);DateTime endDate = pattern.parseDateTime(end);List<DateTime> fridays = new ArrayList<>();boolean reachedAFriday = false;while (startDate.isBefore(endDate)){ if ( startDate.getDayOfWeek() == DateTimeConstants.FRIDAY ){ fridays.add(startDate); reachedAFriday = true; } if ( reachedAFriday ){ startDate = startDate.plusWeeks(1); } else { startDate = startDate.plusDays(1); }}


