I am trying to calculate the number of days between two dates.
First case :
String string = "01/03/2014";
Date dateFin = new SimpleDateFormat("dd/MM/yyyy", Locale.FRANCE).parse(string);
string = "31/03/2014";
Date dateDebut = new SimpleDateFormat("dd/MM/yyyy", Locale.FRANCE).parse(string);
long result = Math.abs(dateFin.getTime() - dateDebut.getTime());
System.out.println((int) (result / (long) (1000 * 3600 * 24)));
=> Result :
29
Second case :
String string = "01/03/2013";
Date dateFin = new SimpleDateFormat("dd/MM/yyyy", Locale.FRANCE).parse(string);
string = "31/03/2013";
Date dateDebut = new SimpleDateFormat("dd/MM/yyyy", Locale.FRANCE).parse(string);
long result = Math.abs(dateFin.getTime() - dateDebut.getTime());
System.out.println((int) (result / (long) (1000 * 3600 * 24)));
=> Result :
30
Question:
Why there is a difference between this two cases?
Thanks