Here you can find the source of getCompareDate(String strDate1, String strDate2, String pFormat)
public static boolean getCompareDate(String strDate1, String strDate2, String pFormat) throws Exception
//package com.java2s; //License from project: GNU General Public License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static boolean getCompareDate(String strDate) throws Exception { SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); Date date = fmt.parse(strDate); return getCompareDate(date, null); }/* ww w .ja va 2 s .co m*/ public static boolean getCompareDate(String strDate1, String strDate2, String pFormat) throws Exception { SimpleDateFormat fmt = new SimpleDateFormat(pFormat); Date date1 = fmt.parse(strDate1); Date date2 = fmt.parse(strDate2); return getCompareDate(date1, date2); } public static boolean getCompareDate(String strDate1, String strDate2) throws Exception { SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); Date date1 = fmt.parse(strDate1); Date date2 = fmt.parse(strDate2); return getCompareDate(date1, date2); } public static boolean getCompareDate(Date pDate) throws Exception { return getCompareDate(pDate, null); } public static boolean getCompareDate(Date pDate1, Date pDate2) throws Exception { Calendar date1 = Calendar.getInstance(); Calendar date2 = Calendar.getInstance(); boolean ret = false; if (pDate1 == null) pDate1 = new Date(); if (pDate2 == null) pDate2 = new Date(); try { date1.setTime(pDate1); date2.setTime(pDate2); ret = date1.before(date2); } catch (Exception e) { } return ret; } }