Java Date Compare getCompareDate(String strDate1, String strDate2, String pFormat)

Here you can find the source of getCompareDate(String strDate1, String strDate2, String pFormat)

Description

get Compare Date

License

Open Source License

Declaration

public static boolean getCompareDate(String strDate1, String strDate2, String pFormat) throws Exception 

Method Source Code

//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;
    }
}

Related

  1. compareYMD(Date begindate, Date enddate)
  2. compDate(Date date1, Date date2)
  3. compDate4(Date date1, Date date2)
  4. getCompareDate(Date startDate, Date endDate)
  5. getCompareDate(String strDate1, String strDate2, String pFormat)
  6. getCompareDateNum(String sDateValue1, String sDateValue2)
  7. getCompareResult(String date1, String date2)
  8. isAfterOrEqual(Date date, Date toCompare)
  9. isBeforeDate(String sCompareDate)