Java Utililty Methods Date Compare

List of utility methods to do Date Compare

Description

The list of methods to do Date Compare are organized into topic(s).

Method

booleancompareDate(String date1, String date2)
compare Date
try {
    Date d1 = formatter.parse(date1);
    Date d2 = formatter.parse(date2);
    return !d1.after(d2);
} catch (ParseException e) {
    e.printStackTrace();
    return false;
booleancompareDate(String s, String e)
compare Date
if (fomatDate(s) == null || fomatDate(e) == null) {
    return false;
return fomatDate(s).getTime() >= fomatDate(e).getTime();
booleancompareDate(String s, String e)
compare Date
if (parseDate(s) == null || parseDate(e) == null) {
    return false;
return parseDate(s).getTime() >= parseDate(e).getTime();
intcompareDate(String sDate, String eDate, String formatStr)
compare Date
Date startDate = strToDate(sDate, formatStr);
Date endDate = strToDate(eDate, formatStr);
return compareDate(startDate, endDate);
longcompareDate(String sFirstDate, String sSecondDate)
compare Date
long time1 = convertDateTimeToSysTime(sFirstDate);
long time2 = convertDateTimeToSysTime(sSecondDate);
long nTime = (time1 - time2);
final long nConst = (24 * 60 * 60 * 1000);
if (nTime % nConst == 0) {
    return nTime / nConst;
return (nTime / nConst) + 1;
...
booleancompareDate(String startdate, String enddate)
compare Date
SimpleDateFormat formatter = new SimpleDateFormat(DEF_DATE_FORMAT);
Date sd = formatter.parse(startdate, new ParsePosition(0));
Date ed = formatter.parse(enddate, new ParsePosition(0));
return sd.before(ed);
intcompareDate(String startDate, String endDate, String strFormat)
compare Date
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(strFormat);
Calendar start = Calendar.getInstance();
Date tempstartdate;
Calendar end = null;
try {
    tempstartdate = formatter.parse(startDate);
    start.setTime(tempstartdate);
    end = Calendar.getInstance();
...
booleancompareDate(String strDate1, String strDate2, String format)
compare Date
Date date1 = convertStrToDate(strDate1, format);
Date date2 = convertStrToDate(strDate2, format);
if (date1.getTime() >= date2.getTime())
    return true;
return false;
booleancompareDate2(String begingDate, String endDate, String format)
compare Date
boolean boo = true;
Date begin = null;
Date end = null;
if (format.isEmpty()) {
    format = format = "yyyy/MM/dd";
DateFormat df = new SimpleDateFormat(format);
if (null == begingDate || "".equals(begingDate)) {
...
booleancompareDateFormat(String strDate1, String strDate2, String format)
compare Date Format
Date date1 = convertStrToDate(strDate1, format);
Date date2 = convertStrToDate(strDate2, format);
if (date1.getTime() > date2.getTime()) {
    return true;
return false;