Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. private void checkTimeframe(int startHour, int startMinute, int endHour, int endMinute) {
  2. LocalDateTime now = LocalDateTime.now();
  3. LocalTime localTimeStart = new LocalTime(startHour, startMinute);
  4. LocalTime localTimeEnd = new LocalTime(endHour, endMinute);
  5.  
  6. LocalDateTime startTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(),
  7. now.getDayOfMonth(), startHour, startMinute);
  8.  
  9. LocalDateTime endTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(),
  10. now.getDayOfMonth(), endHour, endMinute);
  11.  
  12. //Check if start/end is, for instance, 23:00 - 03:00
  13. if (localTimeStart.isAfter(localTimeEnd) || localTimeStart.equals(localTimeEnd)) {
  14. endTime = endTime.plusDays(1);
  15. }
  16.  
  17. if ( (now.equals(startTime) || now.isAfter(startTime) ) && now.isBefore(endTime)) {
  18. System.out.println("Ok, we're within start/end");
  19. } else {
  20. System.out.println("Outside start/end");
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement