Here you can find the source of compareDate(Date date1, Date date2)
public static int compareDate(Date date1, Date date2)
//package com.java2s; /**/* w w w . j av a2s .com*/ * Copyright (C) 2012 Cardinal Info.Tech.Co.,Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Calendar; import java.util.Date; public class Main { public static int compareDate(Date date1, Date date2) { Calendar c1 = Calendar.getInstance(); c1.setTime(date1); Calendar c2 = Calendar.getInstance(); c2.setTime(date2); return compareDate(c1, c2); } public static int compareDate(Calendar cal1, Calendar cal2) { int value = 9; if (cal1.before(cal2)) { value = -1; } if (cal1.after(cal2)) { value = 1; } if (cal1.equals(cal2)) { value = 0; } return value; } }