I am creating a booking system and I don't want to allow users to book with starting time 11:00 and end time 09:00 (past)(I am using 24hour clock). I have two combo boxes filled with Strings that act as start and end time (09:00,10:00,11:00,12:00,13:00....)
I have this code:
String start = (String) startTime.getSelectedItem();
String end = (String) endTime.getSelectedItem();
try {
if(new SimpleDateFormat("hh:mm").parse(start).before(new SimpleDateFormat("hh:mm").parse(end))){
System.out.println("test1");// future date - good
}else{
System.out.println("fail2");// old date - bad
}
} catch (ParseException ex) {
System.out.println("error");
}
This works perfectly except when I pick start/end time to be 12:00. Program outputs opposite of what it is supposed to output and I am unsure why.
If I pick start time 14:00 and end time 12:00 the program will output fail2(good output),
If I pick start time 09:00 and end time 12:00 the program will output fail2(should be test1),
if I pick start time 12:00 and end time 10:00 the program will output test1(should be fail2),
if I pick start time 12:00 and end time 15:00 the program will output test1(good output)
This type of problem only occurs when I pick 12:00..