How to calculate the full difference between two ZonedDateTime
instances with same ZoneId
? In other words difference in all time unites.
Using Java 8 and don't what to use any third party library like Joda
or something else.
ZonedDateTime start = ZonedDateTime.parse("2007-05-11T15:30:00Z");
ZonedDateTime end = ZonedDateTime.parse("2008-03-01T13:00:00Z");
Duration.between(start, end); // PT7077H30M
Period.between(start.toLocalDate(), end.toLocalDate()) // P9M19D
Using Joda-Time
import org.joda.time.DateTime;
import org.joda.time.Period;
DateTime start = DateTime.parse("2007-05-11T15:30:00Z");
DateTime end = DateTime.parse("2008-03-01T13:00:00Z");
Period period = new Period(start, end); // P9M2W4DT21H30M
How get a same result using standard Date/Time API?