做报表统计时需要根据时间统计
/**
* 查询给定时间范围内的每一天的日期(yyyy-MM-dd HH:mm:ss")
*
* @param startDateStr 开始时间 (yyyy-MM-dd HH:mm:ss")
* @param endDateStr 结束时间 (yyyy-MM-dd HH:mm:ss")
* @return List<String>
*/
public static List<String> handleRangeDate(String startDateStr, String endDateStr) {
List<String> listDate = new ArrayList<>();
DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter df2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
try {
LocalDateTime startDate = LocalDateTime.parse(startDateStr, df1);
LocalDateTime endDate = LocalDateTime.parse(endDateStr, df1);
LocalDateTime tempDate = null;
while (!(LocalDateTime.of(startDate.plusDays(-1).toLocalDate(), LocalTime.MIN)
.equals(LocalDateTime.of(endDate.toLocalDate(), LocalTime.MIN)))) {
tempDate = startDate;
String format = tempDate.format(df2);
listDate.add(format);
startDate = startDate.plusDays(1);
}
System.out.println(listDate.toString());
return listDate;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}