Difference of two Joda LocalDateTimes

前端 未结 4 634
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 01:28

I\'ve got 2 Joda LocalDateTime objects and need to produce a 3rd that represents the difference between them:

LocalDateTime start = getStartLoca         


        
4条回答
  •  春和景丽
    2020-12-19 01:46

    You can use org.joda.time.Period class for this - in particular the fieldDifference method.

    Example:

    LocalDateTime endOfMonth = now.dayOfMonth().withMaximumValue();
    LocalDateTime firstOfMonth = now.dayOfMonth().withMinimumValue();
    Period period = Period.fieldDifference(firstOfMonth, endOfMonth)
    

提交回复
热议问题