Period and Duration

If we need to show the amount of time taken e.g 2 days or 3 hours then we need to use the Period and Duration classes introduced in Java 8 time API.

Let’s have a deeper look into these classes.


A period represents the date-based amount of time in the ISO-8601 calendar system, such as 2 years, 3 months, and 4 days. This class is used to modify a given date or to find the difference between dates. We will look at some of the methods provided by this class and how they work.

a) Creating a period

We can create a period using the of() method. There are multiple overloaded variants of the of() method. In the example given below, we will cover the most important ones.

Get hands-on with 1200+ tech skills courses.