Java 8 introduces a concept of TemporalAdjusters. These are essentially time adjusters. You can read
more about these
here.
In order to get the start date of the current month, we first find the current date, and then we
adjust the date using the strategy we need here - which is an adjuster for the first day of the month.
In the Java Time API method naming convention,
with returns a copy of the target object with one element changed. Here the day of month is changed.
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
public final class DateUtility {
private DateUtility() {}
public static LocalDate getStartOfCurrentMonth() {
return LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
}
}