我有array
时间。我每次都从中检索以将其与当前时间进行比较,以便删除经过的时间并制作一个array
包含剩余时间的新时间。
我正在比较从
String timeSlots[] = {"08:00 AM to 08:30 AM", "08:30 AM to 09:00 AM", "09:00 AM to 09:30 AM", "09:30 AM to 10:00 AM", "10:00 AM to 10:30 AM", "10:30 AM to 11:00 AM", "11:00 AM to 11:30 AM", "11:30 AM to 12:00 PM", "12:00 PM to 12:30 PM", "12:30 PM to 01:00 PM", "01:00 PM to 01:30 PM", "01:30 PM to 02:00 PM", "02:00 PM to 02:30 PM", "02:30 PM to 03:00 PM", "03:00 PM to 03:30 PM", "03:30 PM to 04:00 PM", "04:00 PM to 04:30 PM", "04:30 PM to 05:00 PM", "05:00 PM to 05:30 PM", "05:30 PM to 06:00 PM", "06:00 PM to 06:30 PM", "06:30 PM to 07:00 PM", "07:00 PM to 07:30 PM", "07:30 PM to 08:00 PM", "08:00 PM to 08:30 PM", "08:30 PM to 09:00PM"};
for (int i = 0; i < timeSlots.length; i++) {
timeSlotesTemp[i] = timeSlots[i].substring(0, 8);
removeElapsedTime(timeSlotesTemp[i].toLowerCase());
}
public void removeElapsedTime(String elapsedTime) { // elapsedTime = 08:00 pm
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
Date elapsedDate = dateFormat.parse(elapsedTime);
String strElapsedDate=dateFormat.format(elapsedDate);
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
String calculatedDate = dateFormat.format(currentDate);
if (new Date(strElapsedDate).compareTo(new Date(calculatedDate))<0) {
finalTimeSlotes.remove(elapsedTime);
}
else if (new Date(strElapsedDate).compareTo(new Date(calculatedDate))>0) {
finalTimeSlotes.add(elapsedTime);
}
} catch (Exception e) {
Log.e(TAG, "" + e);
}
}
我正在java.lang.IllegalArgumentException: Parse error: 03:30 pm
比较时间