fork download
  1. import java.time.*;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. // A sample date-time corresponding to `time` in code of your question.
  6. // ZoneId.systemDefault() gives you the ZoneId set to the JVM executing the code
  7. // Replace it as per your requirement e.g. ZoneId.of("Europe/Stockholm").
  8. LocalDateTime ldt = LocalDateTime.now(ZoneId.systemDefault());
  9.  
  10. DayOfWeek dow = ldt.getDayOfWeek();
  11. LocalTime time = ldt.toLocalTime();
  12.  
  13. if (dow == DayOfWeek.SATURDAY
  14. || dow == DayOfWeek.SUNDAY
  15. || time.isBefore(LocalTime.of(8, 0))
  16. || time.isAfter(LocalTime.of(20, 0))) {
  17. System.out.println("Not allowed");
  18. // Rest of the processing
  19. } else {
  20. System.out.println("Allowed");
  21. // Rest of the processing
  22. }
  23. }
  24. }
Success #stdin #stdout 0.11s 55864KB
stdin
Standard input is empty
stdout
Allowed