Duration Example Java 8

The Duration (java.time.Duration package) is the amount of time between two Instant’s, between two LocalDateTime or between two LocalTime . Using Duration we measures time in seconds and nanoseconds.

Let see Duration examples to find out difference in seconds

1) Creating Duration Using Instant Example:

Output:

2) Creating Duration Using LocalDateTime Example:

Output:

3) Creating Duration Using LocalTime Example:

Output:

4) Other Way for Creating Duration Example:

Output:

 

Reference:

Leave a Reply

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