Here you can find the source of getBetweenTime(Date begin, Date end, int field)
public static long getBetweenTime(Date begin, Date end, int field)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static long getBetweenTime(Date begin, Date end, int field) { long between = (end.getTime() - begin.getTime()); switch (field) { case Calendar.DATE: return between / (24 * 60 * 60 * 1000); case Calendar.HOUR: return between / (60 * 60 * 1000); case Calendar.MINUTE: return between / (60 * 1000); case Calendar.SECOND: return between / (1000); default://from w w w . j a va2 s . co m return between; } } }