How to calculate difference ONLY in months using Java's Joda API

前端 未结 6 835
忘了有多久
忘了有多久 2020-12-17 21:32

I am writing a program that is supposed to just calculate the months between 2 given dates and return the value to the program. For instance, if I have to calculate the numb

6条回答
  •  抹茶落季
    2020-12-17 21:46

    DateTime start = new DateTime().withDate(2011, 4, 1);
            DateTime end = new DateTime().withDate(2011, 2, 1);
            Period p = new Period(start, end, PeriodType.months().withDaysRemoved());
            int months = p.getMonths();
            System.out.println(months);
    
    
    wrong output in this case
    

提交回复
热议问题