|
@@ -7,6 +7,7 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
@@ -18,6 +19,8 @@ public class DateTimeUtil {
|
|
|
|
|
|
public static String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
|
+ public static String DATE_MONTH = "yyyy-MM";
|
|
|
+
|
|
|
public static LocalDateTime strToLocalDateTime(String str) {
|
|
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT);
|
|
|
return LocalDateTime.parse(str, fmt);
|
|
@@ -28,7 +31,6 @@ public class DateTimeUtil {
|
|
|
return LocalDate.parse(str, fmt);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取当前月的天数
|
|
|
*
|
|
@@ -204,13 +206,23 @@ public class DateTimeUtil {
|
|
|
return retStr;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static List<LocalDate> getBetweenDays(LocalDate startDate, LocalDate endDate) {
|
|
|
+ long numOfDays = ChronoUnit.DAYS.between(startDate, endDate);
|
|
|
+
|
|
|
+ return Stream.iterate(startDate, date -> date.plusDays(1))
|
|
|
+ .limit(numOfDays)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
-// LocalDate startDate = LocalDate.of(2020, Month.JANUARY, 1);
|
|
|
-// LocalDate endDate = LocalDate.of(2021, Month.MARCH, 4);
|
|
|
+ LocalDate startDate = LocalDate.of(2021, Month.MARCH, 1);
|
|
|
+ LocalDate endDate = LocalDate.of(2021, Month.MARCH, 4);
|
|
|
//System.out.println(localDateFormat(LocalDateTime.now(), "yyyy-MM"));
|
|
|
//System.out.println(formatToyyyy_MM_dd(LocalDateTime.now()));
|
|
|
|
|
|
- System.out.println(LocalDate.now().plusDays(-1).atStartOfDay());
|
|
|
+ System.out.println(getBetweenDays(startDate, endDate));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|