I need a method which returns the difference in days between the current day and other any date, I have the following:
private long getDays(Date dateOp) {
Calendar feCurrent=Calendar.getInstance();
feCurrent.set(Calendar.HOUR_OF_DAY, 0);
feCurrent.set(Calendar.MINUTE, 0);
feCurrent.set(Calendar.SECOND, 0);
Calendar feAna=Calendar.getInstance();
feAna.setTime(dateOp);
feAna.set(Calendar.HOUR_OF_DAY, 0);
feAna.set(Calendar.MINUTE, 0);
feAna.set(Calendar.SECOND, 0);
feAna.getTime());
long timeDiff = Math.abs(feAna.getTime().getTime() - feCurrent.getTime().getTime());
return TimeUnit.MILLISECONDS.toDays(timeDiff);
}
The thing is I'm always getting one day less, for example, if the date as parameter is Octuber 16th 2017, the result will 3, but it's actually four, I debugged and the timeDiff for those dates is 345599395 , when converted to days is 3.999....
Does anyone have idea why it's not working.
By the way the date as parameter is load from a database, because if I tried with a main setting both dates it works.