Java 8 - Duration Class API Guide

1. Duration Class Overview

A Duration is most suitable in situations that measure machine-based time, such as code that uses an Instant object.

A Duration object is measured in seconds or nanoseconds and does not use date-based constructs such as years, months, and days, though the class provides methods that convert to days, hours, and minutes. A Duration can have a negative value if it is created with an endpoint that occurs before the start point. Examples of this guide are available on Github.

Duration class provides lots of APIs/Methods to deal with duration. In this post, we will discuss a few important and frequently used Duration APIs/Methods with Examples.