Here you can find the source of compDate4(Date date1, Date date2)
public static int compDate4(Date date1, Date date2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int compDate4(Date date1, Date date2) { Calendar ca1 = Calendar.getInstance(); Calendar ca2 = Calendar.getInstance(); ca1.setTime(date1);//from ww w . j a v a 2s. c o m ca2.setTime(date2); int day1 = ca1.get(Calendar.DAY_OF_MONTH); int year1 = ca1.get(Calendar.YEAR); int month1 = ca1.get(Calendar.MONTH); int day2 = ca2.get(Calendar.DAY_OF_MONTH); int year2 = ca2.get(Calendar.YEAR); int month2 = ca2.get(Calendar.MONTH); ca1.set(year1, month1, day1); ca2.set(year2, month2, day2); int distanceMin = (int) ((ca1.getTimeInMillis() - ca2.getTimeInMillis())); return distanceMin; } }