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);
}
Written by Gautam
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Time
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#