Java 8 – Difference between two LocalDate or LocalDateTime

In Java 8, we can use Period, Duration or ChronoUnit to calculate the difference between two LocalDate or LocaldateTime. Period to calculate the difference between two LocalDate. Duration to calculate the difference between two LocalDateTime. ChronoUnit for everything. 1. Period JavaLocalDate.java package com.mkyong.java8; import java.time.LocalDate; import java.time.Period; public class JavaLocalDate { public static void main(String[] …

Read more

Java 8 – Period and Duration examples

Few examples to show you how to use Java 8 Duration, Period and ChronoUnit objects to find out the difference between dates. Duration – Measures time in seconds and nanoseconds. Period – Measures time in years, months and days. 1. Duration Example A java.time.Duration example to find out difference seconds between two LocalDateTime DurationExample.java package …

Read more