in my android app I have the condition if selected time is greater than 11:00 PM and 07:00 AM then there will be extra charges. it applicable only at night. currently, my code is work correctly but when I am selecting a time in day condition is getting true.
here is my code
Calendar calendar = Calendar.getInstance();
String startDatetime = "11:00 PM";
String endDatetime = "07:00 AM";
SimpleDateFormat formatfornightcharges = new SimpleDateFormat("HH:mm aa");
int Hr24 = calendar.get(Calendar.HOUR_OF_DAY);
try {
Date startDate = formatfornightcharges.parse(startDatetime);
Date selectedTimeforBooking = formatfornightcharges.parse(time_for_night);
Date endDate = formatfornightcharges.parse(endDatetime);
if (selectedTimeforBooking.after(startDate) || selectedTimeforBooking.before(endDate)) {
Toast.makeText(context, "200", Toast.LENGTH_SHORT).show();
night_extra_charges = 200;
tv_text.setText("" + night_extra_charges);
} else {
night_extra_charges = 0;
tv_text.setText("" + night_extra_charges);
Toast.makeText(context, "0", Toast.LENGTH_SHORT).show();
}
} catch (ParseException e) {
e.printStackTrace();
}
}