Compare two dates

5

I have two string containing dates dataSalva and dataDoDia and I'm wondering if dataDoDia and 5 days greater than dataSalva how do I do this

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date data = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(data);
    Date data_atual = cal.getTime();
    String dataDoDia= dateFormat.format(data_atual);

I get this data_completa and saved in the bank Then when I open the application I want to get this date in the bank and compare it with the date of the day, which I will take the same way as the date that was already saved.

String dataSalva = banco.get();

Here's the date that is already saved then I'll do the top part to get the date of the day

I want to compare these two dates dataSalva and dataDoDia

    
asked by anonymous 22.12.2014 / 14:11

1 answer

6

In general everyone recommends using JodaTime which is much better than the original API. But you can do the following:

(DataAtual.getTime() - DataSalva.getTime()) / (1000 * 60 * 60 * 24) == 5
    
22.12.2014 / 14:39