5
When the final date is with the time of 00:00, it identifies that the initial date is greater than the final date only it is not, the initial date remains smaller.
When I set the final date 14/01/2017 23:45
the method returns me -1
. But if I put the final date in effect 14/01/2017 00:45
it returns me 1. This is wrong. How can I resolve this issue?
Example 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!");
}
}
}
That’s all I needed....
– Aline