If you want it to be just a few minutes, why not just specify the right type of period to start with?
private static final PeriodType PERIOD_TO_MINUTES = PeriodType.standard().withSecondsRemoved().withMillisRemoved(); public static String getFormattedDateDifference(DateTime startDate, DateTime endDate) { Period p = new Period(startDate, endDate, PERIOD_TO_MINUTES); return PeriodFormat.getDefault().print(p); }
I expect the format to be what you want.
Note: if they are really for dates, you should probably use PeriodType.yearMonthDay()
and specify the values as LocalDate
. DateTime
should be used for date and time values, not just dates.
source share