fork download
  1. import java.time.ZoneId;
  2. import java.time.ZonedDateTime;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. // Change the time zone ID as per your requirement
  7. ZoneId zoneId = ZoneId.of("Europe/London");
  8. ZonedDateTime now = ZonedDateTime.now(zoneId);
  9.  
  10. int sHour = 21, sMinute = 0, sSecond = 0, sNano = 0;
  11. int eHour = 22, eMinute = 0, eSecond = 0, eNano = 0;
  12.  
  13. ZonedDateTime startTime = now.withHour(sHour)
  14. .withMinute(sMinute)
  15. .withSecond(sSecond)
  16. .withNano(sNano);
  17.  
  18. ZonedDateTime endTime = now.withHour(eHour)
  19. .withMinute(eMinute)
  20. .withSecond(eSecond)
  21. .withNano(eNano);
  22.  
  23. if (!now.isBefore(startTime) && !now.isAfter(endTime)) {
  24. // Silence
  25. // It is from 9:00 PM to 10:00 PM in this example
  26. System.out.println("🤫");
  27. } else {
  28. // The alarm will play
  29. System.out.println("cock-a-doodle-doo");
  30. }
  31. }
  32. }
Success #stdin #stdout 0.14s 59336KB
stdin
Standard input is empty
stdout
🤫