how to get a list of dates between two dates in java

后端 未结 22 1518
余生分开走
余生分开走 2020-11-22 13:24

I want a list of dates between start date and end date.

The result should be a list of all dates including the start and end date.

22条回答
  •  孤街浪徒
    2020-11-22 13:47

    With Joda-Time , maybe it's better:

    LocalDate dateStart = new LocalDate("2012-01-15");
    LocalDate dateEnd = new LocalDate("2012-05-23");
    // day by day:
    while(dateStart.isBefore(dateEnd)){
        System.out.println(dateStart);
        dateStart = dateStart.plusDays(1);
    }
    

    It's my solution.... very easy :)

提交回复
热议问题