fork download
  1. import java.time.LocalDate;
  2. import java.time.LocalDateTime;
  3. import java.time.LocalTime;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. String strStartTime = "22:30:00", strStopTime = "03:30:00", strTestTime = "01:14:23";
  8. LocalDate today = LocalDate.now();
  9.  
  10. LocalDateTime startTime = today.atTime(LocalTime.parse(strStartTime));
  11.  
  12. LocalDateTime stopTime = today.atTime(LocalTime.parse(strStopTime));
  13. if (stopTime.isBefore(startTime))
  14. stopTime = stopTime.plusDays(1);
  15.  
  16. LocalDateTime testTime = today.atTime(LocalTime.parse(strTestTime));
  17. if (testTime.isBefore(startTime))
  18. testTime = testTime.plusDays(1);
  19.  
  20. if (!testTime.isBefore(startTime) && !testTime.isAfter(stopTime))
  21. System.out.println(strTestTime + " is at or after " + strStartTime + " and is before or at " + strStopTime);
  22. }
  23. }
Success #stdin #stdout 0.19s 57664KB
stdin
Standard input is empty
stdout
01:14:23 is at or after 22:30:00 and is before or at 03:30:00