Here you can find the source of getHour(Date begin, Date end)
public static int getHour(Date begin, Date end)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getHour(Date begin, Date end) { Calendar c1 = Calendar.getInstance(); c1.setTime(begin);// www .j av a2 s. c om Calendar c2 = Calendar.getInstance(); c2.setTime(end); Long millisecond = c2.getTimeInMillis() - c1.getTimeInMillis(); Long hour = millisecond / 1000 / 60 / 60; Long minute = (millisecond / 1000 / 60) % 60; if (minute >= 30) { hour++; } return hour.intValue(); } }