Joda time - all mondays between two dates

前端 未结 6 1954
我寻月下人不归
我寻月下人不归 2020-12-16 03:36

I am using Joda time api in a Spring 3.0 project for the very first time. Now I have a start and end date and I want to get the date for all mondays between these two dates.

6条回答
  •  轮回少年
    2020-12-16 04:03

    import java.time.LocalDate;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Get_time {
    
        public  ArrayList getmondays(String s,String e)
        {
            LocalDate start = LocalDate.parse(s);
            LocalDate end = LocalDate.parse(e);
            List totalDates_Mondays = new ArrayList<>();
    
            while (!start.isAfter(end)) {
                totalDates_Mondays.add(start);
                start = start.plusWeeks(1);
            }
            return (ArrayList) totalDates_Mondays;
        }
    
        public static void main(String ...s1) {
    
            String mon_start = "1600-08-01";
            String mon_end= "2016-12-29";
            Get_time t=new Get_time();
            System.out.println(t.getmondays(mon_start,mon_end));
        }
    }
    

提交回复
热议问题