I know how to express an amount of days in Java by using the java.time.Period
class. But how can I express an specific time period in history, like "the seven days between March 23, 2012 and March 30 2012", and not just "seven days"?
To illustrate, in the code bellow p1
and p2
are created as distinct "time periods in history", both spanning exactly seven days but with the former in March 2012 and the later in April 2014.
java.time.Period p1 = Period.between(
LocalDate.of(2012, Month.MARCH, 23),
LocalDate.of(2012, Month.MARCH, 30));
java.time.Period p2 = Period.between(
LocalDate.of(2014, Month.APRIL, 1),
LocalDate.of(2014, Month.APRIL, 8));
As instances of java.util.Period
, they are nevertheless equals
to each other
//returns true!
boolean isTheSamePeriod = p1.equals(p2);
What would be the class to represent a certain amount of days from an specific starting date?