判断当前日期是否在两个日期范围之内
public static boolean isBetween(LocalDateTime beginTime, LocalDateTime endTime) { LocalDateTime now = LocalDateTime.now(); boolean flag = false; if (now.isAfter(beginTime) && now.isBefore(endTime)) { flag = true; } return flag; }
public static void main(String[] args) { DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String a = "2022-09-06 17:17:57"; String b = "2022-09-06 18:17:57"; System.out.println(isBetween(LocalDateTime.parse(a,df),LocalDateTime.parse(b,df))); }