Given 2 dates, how can I calculate the difference between them in Year Month Day, Hour Minute Second format, as per ISO 8601 Durations?
I've only found Java libraries that can give the difference in days or smaller.
Given that months and years have irregular numbers of days, I'm not sure how to figure out the difference in months and years.
Even Duration.between() is close, but it gives the result in hours minutes seconds:
ZonedDateTime event1 = ZonedDateTime.of(2022, 2, 2, 2, 2, 2, 0, ZoneId.of("UTC-7"));
ZonedDateTime event2 = ZonedDateTime.of(2025, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC-7"));
//ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC-7"));
Duration duration = Duration.between(event1, event2);
Log.d("Duration ISO-8601: ", duration.toString());
Output: PT25533H57M58S
Which is 25533 hours, 57 minutes, 58 seconds.
I'd like to see something like:
__ years, __ months, __ days, 9 hours, 57 minutes, 58 seconds