Last Updated: February 25, 2016
·
887
· gautamnitish

Time difference in hours .

I usually hate reinventing the wheel, but I just couldn't get myself to use a library for this.

import java.util.Date;
public static final long MILLISECONDS_IN_AN_HOUR = 3600000;
public static int TimeDiffernceInhours(Date d1, Date d2) {
    long diffInMills = Math.abs(d1.getTime() - d2.getTime());
    return (int) (diffInMills / MILLISECONDS_IN_AN_HOUR);
}