SHARE
TWEET

Untitled

a guest Jun 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top