Incorrect jodatime period - years months days

前端 未结 1 1331
慢半拍i
慢半拍i 2020-12-12 03:00

I created a Utility method using jodatime to calculate date difference and display it such as 3y 2m 4d.

Here is my method:

public static String date         


        
相关标签:
1条回答
  • 2020-12-12 03:48

    Unfortunately the standard period type in Joda Time includes weeks (yes - not intuitive at all, so it is not sufficient just to write new Period(from, to), but to use the alternative 3-args-constructor with an explicit period type argument where you specify only years, months and days.

    Solution:

    Period period = 
      new Period(new LocalDate(start), new LocalDate(end), PeriodType.yearMonthDay());
    
    0 讨论(0)
提交回复
热议问题