Here you can find the source of getTimeBeetweenDates(Date d1, Date d2, int timeType)
public static long getTimeBeetweenDates(Date d1, Date d2, int timeType)
//package com.java2s; /*//from w w w . j a va 2s . c o m * Copyright (C) 2010 dungnv. All rights reserved. * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.Calendar; import java.util.Date; public class Main { public static long getTimeBeetweenDates(Date d1, Date d2, int timeType) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(d1); cal2.setTime(d2); long diff = d2.getTime() - d1.getTime(); switch (timeType) { case Calendar.SECOND: return (long) diff / 1000; case Calendar.MINUTE: return (long) diff / (60 * 1000); case Calendar.HOUR: return (long) diff / (60 * 60 * 1000); case Calendar.DATE: return (long) diff / (24 * 60 * 60 * 1000); default: return diff; } } }