public static void main(String[] args) throws Exception{ Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date b = df.parse("2022-08-17 15:00:00"); Date e = df.parse("2022-08-17 15:11:00"); Calendar dateC = Calendar.getInstance(); dateC.setTime(date); Calendar begin = Calendar.getInstance(); begin.setTime(b); Calendar end = Calendar.getInstance(); end.setTime(e); if (dateC.after(begin) && dateC.before(end)) { System.out.println("在区间里"); }else{ System.out.println("不在区间里"); } boolean after = date.after(b); boolean before = date.before(e); if (after && before) { System.out.println("在区间里"); }else{ System.out.println("不在区间里"); } LocalDateTime now = LocalDateTime.now(); LocalDateTime beginTime = LocalDateTime.of(2022, 8, 17, 15, 0, 0); LocalDateTime endTime = LocalDateTime.of(2022, 8, 17, 15, 11, 0); if (now.isAfter(beginTime) && now.isBefore(endTime)) { System.out.println("在区间里"); }else{ System.out.println("不在区间里"); } }