whyclxw
7 天以前 a6018ae593fc2d2fb3ccfa4e7c34f28387326f6b
src/main/java/com/whyc/util/ActionUtil.java
@@ -18,6 +18,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -27,6 +28,7 @@
   public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
   public static String time_yyyyMMdd = "yyyy-MM-dd";
   public static String time_yyyyMM = "yyyy-MM";
   public static String time_yyyyMMdd_HH_mm_ss = "yyyy-MM-dd_HH_mm_ss";
   public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   public static SimpleDateFormat sdfwithOutday = new SimpleDateFormat("yyyy_MM");
@@ -637,5 +639,27 @@
      }
      return lang;
   }
     //两时间之间的年月集合
   public static List<String> getDateListBetweenDates(Date startTime, Date endTime) {
      // 指定开始日期和结束日期
      LocalDate startDate = LocalDate.of(startTime.getYear() + 1900, startTime.getMonth() + 1, startTime.getDay()); // 示例起始日期
      LocalDate endDate = LocalDate.of(endTime.getYear() + 1900, endTime.getMonth() + 1, endTime.getDay());  // 示例结束日期
      List<String> dateList = new ArrayList<>();
      LocalDate currentDate = startDate;
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ActionUtil.time_yyyyMM);
      while (!currentDate.isAfter(endDate)) {
         String formattedDate = currentDate.format(formatter);
         dateList.add(formattedDate);
         currentDate = currentDate.plusMonths(1);
      }
      return dateList;
   }
   public static void main(String[] args) throws ParseException {
      List<String> dateList =getDateListBetweenDates(ActionUtil.sdf.parse("2025-01-01 00:00:00"),new Date());
      for (String date : dateList) {
         System.out.println(date);
      }
   }
}