Java tutorial
//package com.java2s; //License from project: Open Source License import android.text.format.DateUtils; public class Main { /** * Calculates how many hours are in given period. If one of the dates only partially covers the hour, it still counts as full hour. * * @param start Start of the period. * @param end End of the period. * @return Number of days in given period. If {@code end < start}, returns -1. */ public static int getHourCountInPeriod(long start, long end) { if (end < start) return -1; return (int) Math.ceil((double) (end - start) / DateUtils.HOUR_IN_MILLIS); } }