hi i need to get all the start dates and end date of each and every month in between given two years
pulbic void printStartDateAndEndDate(Date start, Date e
Using JodaTime...
LocalDate startDate = new LocalDate(2011, 11, 8);
LocalDate endDate = new LocalDate(2012, 5, 1);
startDate = startDate.withDayOfMonth(1);
while (!startDate.isAfter(endDate)) {
System.out.println("> " + startDate);
startDate = startDate.plusMonths(1);
LocalDate endOfMonth = startDate.minusDays(1);
System.out.println("< " + endOfMonth);
}
Using Java 8's time
API
LocalDate startDate = LocalDate.of(2011, 11, 8);
LocalDate endDate = LocalDate.of(2012, 5, 1);
startDate = startDate.withDayOfMonth(1);
while (!startDate.isAfter(endDate)) {
System.out.println("> " + startDate);
startDate = startDate.plusMonths(1);
LocalDate endOfMonth = startDate.minusDays(1);
System.out.println("< " + endOfMonth);
}