java
复制代码
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class DateUtils {
public static List<String> getDatesBetween(String startDateStr, String endDateStr) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate startDate = LocalDate.parse(startDateStr, formatter);
LocalDate endDate = LocalDate.parse(endDateStr, formatter);
List<String> dates = new ArrayList<>();
//这里是判断开始日期是否在结束日期之后或者=结束日期
while (startDate .isBefore(endDate) || startDate .isEqual(endDate)) {
String add = startDate .format(formatter);
dates.add(add);
startDate = startDate .plusDays(1);
}
return dates;
}
}