I have two Date objects and I need to get the time difference so I can determine the total hours between them. They happen to be from the same day. The result I would like w
Even though there's already an accepted answer, this is what worked for me using the Joda time library.
/**
*
* @param date1
* @param date2
* @return hours between two dates rounded down
*/
public static int hoursBetween(DateTime date1, DateTime date2) {
if(date1 == null || date2 == null) return NOT_FOUND;
return Math.abs(Hours.hoursBetween(date1.toLocalDateTime(), date2.toLocalDateTime()).getHours());
}