I’m wondering if there is a more efficient way to do this, from a CPU time standpoint:
/*
* Returns a string in the form of "n days, x hours, y minutes"
* */
public static String getFormattedDateDifference(DateTime startDate, DateTime endDate) {
Period p = new Period(startDate, endDate,
PeriodType.standard().withSecondsRemoved().withMillisRemoved());
return PeriodFormat.getDefault().print(p);
}
This, maybe?
With this simple
main(), it shows a more than double speedup:383 ms for the original function, 150 ms for mine.