I have 2 methods to get the difference of days between 2 dates. The first is:
public static int getDiffDays(Date dateOne, Date dateTwo){
Long timeOne = dateOne.getTime();
Long timeTwo = dateTwo.getTime();
long diff = timeOne - timeTwo ;
return (int) (diff / (24 * 60 * 60 * 1000));
}
The other one is:
public static long getDiffTimeUnit(Date dateOne, Date dateTwo, TimeUnit unit){
return unit.convert((dateOne.getTime() - dateTwo.getTime()), TimeUnit.MILLISECONDS);
}
Both methods return me a wrong value when the dates have 1 day of difference, otherwise they return the right value. So for example with these 2 dates:
Mon Aug 01 00:00:00 GMT+02:00 2022 Tue Aug 02 00:00:00 GMT+02:00 2022
They return me 0 day of difference instead of 1...
But with these 2 dates:
Mon Aug 08 00:00:00 GMT+02:00 2022 Wed Aug 31 00:00:00 GMT+02:00 2022
They return me 23 days of difference that is correct.
How can I resolve this issue? (I cannot use ChronoUnit because it requires API 26)
Thank you



