日期区间
import com.example.demo.dto.QueryRangTimeDto;import lombok.extern.slf4j.Slf4j;import java.time.LocalDate;import java.time.format.DateTimeFormatter;/** * @author HUAWEI */@Slf4jpublic class SumTestController { private final static String MIN_TIME = "2021-07-01"; public static void main(String[] args) { QueryRangTimeDto condition = new QueryRangTimeDto("2021-09-01", "2021-09-20"); LocalDate startTime = LocalDate.parse(condition.getStartMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); LocalDate endTime = LocalDate.parse(condition.getEndMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); if (!startTime.isBefore(endTime)) { if (!startTime.isEqual(endTime)) { log.info("请输入正常日期"); return; } } boolean begin = getBelongDate(startTime); boolean end = getBelongDate(endTime); if (begin && end) { log.info("正常查询"); return; } log.info("请输入正常日期"); } /** * 判断时间是否在某段时间内 * * @return 比较结果 */ public static boolean getBelongDate(LocalDate now) { //时间当前年 int year = LocalDate.now().getYear(); //自定义开始时间 LocalDate begin = LocalDate.of(year, 7, 1); //自定义结束时间 LocalDate end = LocalDate.of(year, 9, 20); return now.isAfter(begin) && now.isBefore(end); }}