I try to get the correct difference time between the current day and second selected day from the calendar.
I'm using in this case LocalDate
and the 3 methods getDays()
getMonths()
getYears()
to get the day and the month also the year:
public int dateDiff(int year,int month,int day) {
final int Day = c.get(Calendar.DAY_OF_MONTH);
final int Month = c.get(Calendar.MONTH);
final int Year = c.get(Calendar.YEAR);
LocalDate localDate1 = LocalDate.of(year,month,day);
LocalDate localDate2 = LocalDate.of(Year,Month,Day);
Period period = Period.between(localDate2,localDate1);
int dayDiff = period.getDays();
return dayDiff;
}
public void onSelectedDayChange(@NonNull CalendarView view, final int year, final int month, final int dayOfMonth) {
textView.setText(""+dateDiff(year, month, day));
}
But each time when I test the code I got in the textView "0" I try to see the value of the variable "period" and I got (P2M8D 'this result got in my example') that's mean the variable period count the difference between the days and the problem in the methods. How can I solve this problem?