import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;

public class Main {
	public static void main(String[] args) {
		// Test
		System.out.println(monthsBetween(LocalDate.of(2012, 1, 28), LocalDate.of(2012, 2, 1)));
		System.out.println(monthsBetween(LocalDate.of(2012, 2, 27), LocalDate.of(2012, 2, 28)));
		System.out.println(monthsBetween(LocalDate.of(2012, 3, 28), LocalDate.of(2012, 7, 1)));
	}

	static int monthsBetween(final LocalDate fromDate, final LocalDate toDate) {
		return Math.toIntExact(
					ChronoUnit.MONTHS.between(
							fromDate.with(TemporalAdjusters.firstDayOfMonth()),
							toDate.with(TemporalAdjusters.firstDayOfMonth())
					)
				);
	}
}