How in Android can I get and display the number of days, months, and years since a date?
For example, let's say the previous date is:
02/02/2017
and today's date is:
04/30/2018
I would want it to say something like:
1 year, 2 months, 28 days
I think I need to get total days like so:
long msDiff = Calendar.getInstance().getTimeInMillis() - oldCalendarDate.getTimeInMillis();
long daysDiff = TimeUnit.MILLISECONDS.toDays(msDiff);
but how do I convert the amount of days to be legible as years, months, and days? Keeping in mind that not all months have 31 days.
Because this way, I am only getting
452 days
As the result. But I want it to be more like 1 year, 2 months, 28 days.
Is there a better solution?
Also I want to get the old date like so in a variable:
val oldCalendarDate = GregorianCalendar(2017, 3, 30).time
but it's not working at all with the above code. Yes I'm aware that variable is in kotlin because I'm working in kotlin so pardon the syntax. I think the more issue about this is how the integers are formatted. I already converted the other java code to kotlin but I posted it as java for this post since more people are familiar with java.