[Solved] Subtracting months in Java [closed]


The simplest approach is to use ChronoUnit#between method:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "MMMM dd, yyyy", Locale.US );
LocalDate d1 = LocalDate.parse( "May 28, 2019", formatter );
LocalDate d2 = LocalDate.parse( "September 02, 2020", formatter );

long diff = ChronoUnit.MONTHS.between( d1, d2 );   // 15 full months

1

solved Subtracting months in Java [closed]