Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void checkTimeframe(int startHour, int startMinute, int endHour, int endMinute) {
- LocalDateTime now = LocalDateTime.now();
- LocalTime localTimeStart = new LocalTime(startHour, startMinute);
- LocalTime localTimeEnd = new LocalTime(endHour, endMinute);
- LocalDateTime startTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(),
- now.getDayOfMonth(), startHour, startMinute);
- LocalDateTime endTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(),
- now.getDayOfMonth(), endHour, endMinute);
- //Check if start/end is, for instance, 23:00 - 03:00
- if (localTimeStart.isAfter(localTimeEnd) || localTimeStart.equals(localTimeEnd)) {
- endTime = endTime.plusDays(1);
- }
- if ( (now.equals(startTime) || now.isAfter(startTime) ) && now.isBefore(endTime)) {
- System.out.println("Ok, we're within start/end");
- } else {
- System.out.println("Outside start/end");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement