| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | | /** |
| | | * 日期时间工具类 |
| | |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); |
| | | return dateFormat.parse(dateStr); |
| | | } |
| | | |
| | | /** |
| | | * 获取前30天所有日期 |
| | | * @param pattern |
| | | * @return |
| | | */ |
| | | public static List<String> getLastMonthDays(String pattern) { |
| | | LocalDate today = LocalDate.now().minusDays(1); |
| | | LocalDate oneMonthAgo = today.minusMonths(1); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); |
| | | return IntStream.iterate(0, i -> i + 1) |
| | | .limit(ChronoUnit.DAYS.between(oneMonthAgo, today) + 1) |
| | | .mapToObj(oneMonthAgo::plusDays) |
| | | .map(date -> date.format(formatter)) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 日期型字符串转化为日期 格式 |
| | |
| | | return newDate; |
| | | } |
| | | } |
| | | |