编辑代码

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

class Main {
	public static void main(String[] args) throws ParseException {
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = dateformat.parse("2023-03-12");
        Date endDate = dateformat.parse("2023-03-14");
        //System.out.println(dateformat.format(startDate));
        //System.out.println(dateformat.format(endDate));
        getBetweenDayList(dateformat,startDate,endDate);
	}

    public static List<Date> getBetweenDayList(SimpleDateFormat dateformat, Date start, Date end) {
        List<Date> resultList = new ArrayList<Date>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
            for (long d = cal.getTimeInMillis(); d <= end.getTime(); d = getNextDay(cal).getTime()) {
                Date newDate= new Date(d);
                System.out.println(dateformat.format(newDate));
                resultList.add(newDate);
            }
        Collections.reverse(resultList);
        return resultList;
    }

    public static Date getNextDay(Calendar c) {
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
        return c.getTime();
    }
}