Java 8 Period Example

A Period (java.time.Period package) is the amount of time between two LocalDate ,measuring time in years, months and days. Let see Period by different example:

1) Period Example:


2) Period Example:

 Sardar Patel was born October 31st,1875. If I want to know amount of time in Years, month and days since Sardar Patel was born? I can create Period like below.

I am creating a Period between his date of birth and now, until is method which is used to create Period of time until now. And If I want to number of time passed in years I need to call getYears() method.



I can also call until method with special unit ChronoUnit.DAYS then it will return me long which is number of days since Sardar Patel was born.



Check Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *