I have two times opening and close. I want to generate as much slot which can be accommodate within defined range with fixed number of minutes. For e.g opening time: 12:30 pm and close timing: 3:30 pm respectively. So in this particular range i have to add minutes let's say 15 min increment every time until the time reaches to close time. Like 12:45, 12:30, ........ , 3:15, 3:30 pm exactly here i want to finish the loop but in my case it goes up to 12:06 am from 12:30 pm
String newTime = "";
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
Date date = dateFormat.parse(_model.getClinic_time_from());
SimpleDateFormat dateFormat1 = new SimpleDateFormat("hh:mm a");
Date date1 = dateFormat1.parse(_model.getClinic_time_to());
Date temp = date;
while (date1.compareTo(temp) < 0)
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(temp);
calendar.add(Calendar.MINUTE, Integer.parseInt(_model.getSlot()));
newTime = dateFormat.format(calendar.getTime());
Apt_time_model ap = new Apt_time_model(dateFormat.format(temp.getTime()),newTime,"no status");
Apt_time_model ap1 = new Apt_time_model(ap.getApt_time_from(), ap.getApt_time_to(),ap.getStatus());
list.add(ap1);
temp = dateFormat.parse(newTime);
}