How do I obtain the number of days within a given month using Joda-Time?

后端 未结 4 1260
离开以前
离开以前 2020-12-28 12:04
30 days hath September,
   April, June and November,
 All the rest have 31,
   Excepting February alone
(And that has 28 days clear,
   With 29 in each leap year).
<         


        
4条回答
  •  余生分开走
    2020-12-28 12:08

    Here is another simple function:

    int daysOfMonth(DateTime dt) {
        int month = dt.getMonthOfYear();
        int month2 = month;
        int days = dt.getDay();
        DateTime dt2 = dt;
        while (month == month2 ) {
           days++;
           dt2.addDays(1);
           month2 = dt2.getMonthOfYear();
        }
        return (days - 1);
    }
    

提交回复
热议问题