I am trying to display a custom text result between two dates. Here is the code in my Fragment, which return two dates:
public class HomeFragment extends BaseFragment {
...
dashboardViewModel.productCategory.observe(this, data - > {
if (data != null && data.getData() != null) {
int totalLos = Integer.parseInt(data.getData().getLos());
Log.e("totalLOS", String.valueOf(totalLos));
explainDays(totalLos);
mBinding.los.setText("");
}
});
}
And here the code in BaseFragment which generate two dates:
public abstract class BaseFragment extends Fragment {
...
public void explainDays(int totalDays) {
Calendar calendar = Calendar.getInstance();
Date start = calendar.getTime();
calendar.add(Calendar.DATE, -totalDays);
Date end = calendar.getTime();
Log.e("startDate", String.valueOf(start));
Log.e("endDate", String.valueOf(end));
}
}
From the code above, I am getting these three logs:
E/totalLOS: 1233
E/startDate: Mon Jun 08 19:45:08 GMT+07:00 2020
E/endDate: Sun Jan 22 19:45:08 GMT+07:00 2017
How do I generate a response like for example 1 Year and 5 Months since 2007 between these two date results? the since 2007 needs to be extracted from endDate from Log above.
Any help will be much appreciated.
Thank you.