When the end date is with the 00:00 time, it identifies that the start date is longer than the end date but it is not, the start date is still shorter.
When I put the end date using 14/01/2017 23:45
the method returns me -1
. But if I put end date with 14/01/2017 00:45
it returns me 1. This is wrong. How can I resolve this issue?
Sample class:
public class Hora {
public static void main(String[] args) {
Date dataInicial = null;
Date dataFinal = null;
String datafinal = "14/01/2017 00:45";
//Aqui eu pego a hora atual.
Calendar c = Calendar.getInstance();
dataInicial = c.getTime();
//System.out.println(dataInicial);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
try {
dataFinal = sdf.parse(datafinal);
} catch (Exception e) {
}
//datafinal = sdf.format(dataFinal);
System.out.println(dataInicial.compareTo(dataFinal));
if(dataInicial.compareTo(dataFinal) < 0){
System.out.println("tudo ok!");
}
}
}