I'm trying to convert a Milliseconds date to number of years
months
weeks
and days
.
For example: 5 months, 2 weeks and 3 days
or 1 year and 1 day
.
I don't want: 7 days
or 4 weeks
> this should be 1 week
and 1 month
.
I tried few ways but it always became something like 7 days and 0 weeks
.
My code:
int weeks = (int) Math.abs(timeInMillis / (24 * 60 * 60 * 1000 * 7));
int days = (int) timeInMillis / (24 * 60 * 60 * 1000)+1);
I have to add 1 to number of days because if I have 23 hours it should be 1 day.
Please explain how to convert it correctly, I think that there is more efficient ways to do it.