Here you can find the source of calcTime(Date end, Date start, int calendarField)
public static long calcTime(Date end, Date start, int calendarField)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { public static long calcTime(Date end, Date start, int calendarField) { if (end == null || start == null) return 0; long diff = end.getTime() - start.getTime(); switch (calendarField) { case Calendar.MILLISECOND: return diff; case Calendar.SECOND: return diff / 1000; case Calendar.MINUTE: return diff / (1000 * 60); case Calendar.HOUR: return diff / (1000 * 60 * 24); default://from ww w.ja v a2 s .c om throw new RuntimeException("Not support."); } } }