// Check Time between 2 times
public static boolean getWorkingHours(String currentTime) {
boolean isWorkingHour = false;
try {
String string1 = "09:00:00";
Date time1 = new SimpleDateFormat("HH:mm:ss").parse(string1);
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(time1);
String string2 = "18:00:00";
Date time2 = new SimpleDateFormat("HH:mm:ss").parse(string2);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(time2);
calendar2.add(Calendar.DATE, 1);
// String someRandomTime = "01:00:00";
Date d = new SimpleDateFormat("HH:mm:ss").parse(currentTime);
Calendar calendar3 = Calendar.getInstance();
calendar3.setTime(d);
calendar3.add(Calendar.DATE, 1);
Date x = calendar3.getTime();
if (x.after(calendar1.getTime()) && x.before(calendar2.getTime())) {
//checkes whether the current time is between 14:49:00 and 20:11:13.
isWorkingHour = true;
Log.e("", "==========> Is Woking Hour");
} else {
Log.e("", "==========> Is Not Woking Hour");
isWorkingHour = false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return isWorkingHour;
}
public static boolean getWorkingHours(String currentTime) {
boolean isWorkingHour = false;
try {
String string1 = "09:00:00";
Date time1 = new SimpleDateFormat("HH:mm:ss").parse(string1);
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(time1);
String string2 = "18:00:00";
Date time2 = new SimpleDateFormat("HH:mm:ss").parse(string2);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(time2);
calendar2.add(Calendar.DATE, 1);
// String someRandomTime = "01:00:00";
Date d = new SimpleDateFormat("HH:mm:ss").parse(currentTime);
Calendar calendar3 = Calendar.getInstance();
calendar3.setTime(d);
calendar3.add(Calendar.DATE, 1);
Date x = calendar3.getTime();
if (x.after(calendar1.getTime()) && x.before(calendar2.getTime())) {
//checkes whether the current time is between 14:49:00 and 20:11:13.
isWorkingHour = true;
Log.e("", "==========> Is Woking Hour");
} else {
Log.e("", "==========> Is Not Woking Hour");
isWorkingHour = false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return isWorkingHour;
}