Skip to content

Tag: java-8

Java 8 calculate how many 1st of the months between two dates

I have two dates: I want the result = 1 (for the date, 2022-04-01) Answer tl;dr See this code run live at IdeOne.com. 1 Details First, parse the inputs as LocalDate objects. The LocalDate#datesUntil method creates a stream of LocalDate objects between the two values. We can filter that stream to keep only the…