Given a list with timetables eg: String [] schedules = {"11:00", "12:00", "13:00"};
I want to pick up my current time and compare it to the list next time, ie current time is 11:30 am, I get the "12:00" list.
Given a list with timetables eg: String [] schedules = {"11:00", "12:00", "13:00"};
I want to pick up my current time and compare it to the list next time, ie current time is 11:30 am, I get the "12:00" list.
To compare dates you should use Android Calendar.
Calendar horaComparar = Calendar.getInstance();
horaComparar.setTime(new SimpleDateFormat("h:mm").parse(horarios[0]));
Date horaAtual = new Date(System.currentTimeMillis());
if (horaComparar.getTime().compareTo(horaAtual) > 0 ){
// hora é posterior a hora Atual.
}
- The return value is 0 if both dates are equal.
- The return value is greater than 0 if the date is later than the argument date.
- The return value is less than 0 if the date is preceding the date argument.
If you're referring to the java.sql.Time
class, then just use the method valueOf(String)
:
String hora1 = "23:00";
Time n1 = Time.valueOf(hora1 + ":00");
String hora2 = "02:15";
Time n2 = Time.valueOf(hora2 + ":00");
if (n1.after(n2))...
If you're using android.text.format.Time
, then see javadoc:
This class was deprecated in API level 22.
UseGregorianCalendar
instead.
That translating into Portuguese is:
This class has been deprecated in API level 22.
UseGregorianCalendar
instead.