/**
* @author lautturi.com
* Java example: compute the number of months between two dates in java
*/
import java.util.*;
import java.time.LocalDate;
import java.time.temporal.*;
public class Lautturi {
public static void main(String[] args){
LocalDate start = LocalDate.parse("2020-10-13");
LocalDate end = LocalDate.parse("2021-11-05");
long diff = ChronoUnit.MONTHS.between(start, end);
System.out.println("months between two dates: " + diff);
}
}
output:
months between two dates: 12