try this method:
public static int getDateCount(LocalDate startDate, LocalDate endDate, final int index) {
long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate);
return IntStream.iterate(0, i -> i + 1)
.limit(numOfDaysBetween)
.mapToObj(i -> startDate.plusDays(i))
.filter(i -> i.getDayOfMonth() == index)
.collect(Collectors.toList()).size();
}
usage:
public static void main(String[] args){
LocalDate startDate = LocalDate.of(2019,1,1);
LocalDate endDate = LocalDate.of(2019,1,31);
int index=1;
System.out.println(getDateCount(startDate,endDate,index));
}
output:
1
Here i first calculated days between two dates then extracted all days occuring between these dates then filtered them to desired day e.g 1 in that case.
Note : that might not be the best and effective solution