Here you can find the source of areDatesOneMonthApart(LocalDateTime start, LocalDateTime end)
public static boolean areDatesOneMonthApart(LocalDateTime start, LocalDateTime end)
//package com.java2s; //License from project: Open Source License import java.time.*; public class Main { public static boolean areDatesOneMonthApart(LocalDateTime start, LocalDateTime end) { final int startDay = start.getDayOfMonth(); final int endDay = end.getDayOfMonth(); if (startDay == endDay && (start.getMonth() != start.getMonth())) { return true; } else {/*from w w w . ja v a2 s. c o m*/ // could be because one of the two is the last day of the month final boolean startAtMonthEnd = (startDay == start.getMonth().length(start.toLocalDate().isLeapYear())); final boolean endAtMonthEnd = (endDay == end.getMonth().length(end.toLocalDate().isLeapYear())); if (startAtMonthEnd) { return endAtMonthEnd || endDay > startDay; // i.e., either both are month ends, or end day is 'usual' day and start day was month-constrained } else { return endAtMonthEnd && endDay < startDay; // i.e., this is a short month (and since above has evaluated false, can't be both at month end } } } }