In the code snipet below, it is being verified that if the current time (can be any) exists between start and end time or not:
Calendar startTimeCal = Calendar.getInstance();
startTimeCal.setTime(startTime);
int startTimeHour = startTimeCal.get(Calendar.HOUR_OF_DAY);
if (startTimeHour == 0){
startTimeHour = 24;
}
int startTimeMinutes = startTimeCal.get(Calendar.MINUTE);
Calendar curTimeCal = Calendar.getInstance();
curTimeCal.setTime(currentTime);
int curTimeHour = curTimeCal.get(Calendar.HOUR_OF_DAY);
int curTimeMinutes = curTimeCal.get(Calendar.MINUTE);
Calendar endTimeCal = Calendar.getInstance();
endTimeCal.setTime(endTime);
int endTimeHour = endTimeCal.get(Calendar.HOUR_OF_DAY);
if (endTimeHour == 0) {
endTimeHour = 24;
}
int endTimeMinutes = endTimeCal.get(Calendar.MINUTE);
if (((curTimeHour > startTimeHour) || (curTimeHour == startTimeHour && curTimeMinutes >= startTimeMinutes)) &&
((curTimeHour < endTimeHour) || (curTimeHour == endTimeHour && curTimeMinutes <= endTimeHour))) {
//time exists between start and end time
} else {
//time doesn't exist between start and end time
}