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

booleangetCompareResult(String date1, String date2)
get Compare Result
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(strToDate(date1));
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(strToDate(date2));
if (calendar2.after(calendar1)) {
    return true;
return false;
...
booleanisAfterOrEqual(Date date, Date toCompare)
Returns true if toCompare is after or on same day as date.
if (date == null || toCompare == null) {
    return false;
date = zeroTime(date);
toCompare = zeroTime(toCompare);
return toCompare.compareTo(date) <= 0;
booleanisBeforeDate(String sCompareDate)
is Before Date
SimpleDateFormat clsFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
    Date compareDate = clsFormat.parse(sCompareDate);
    Date currentDate = clsFormat.parse(clsFormat.format(new Date()));
    if (currentDate.before(compareDate)) {
        return true;
} catch (ParseException e) {
...
booleanisInDate(Date date, Date compareDate)
is In Date
if (compareDate.after(getStartDate(date)) && compareDate.before(getFinallyDate(date))) {
    return true;
} else {
    return false;
Datemax(Collection datumok)
max
Collection<Date> nemNullDatumok = new ArrayList<Date>();
for (Date date : datumok) {
    if (date != null) {
        nemNullDatumok.add(date);
Date max = nemNullDatumok.isEmpty() ? null : Collections.max(nemNullDatumok);
return max;
...
Datemax(Date a, Date b)
max
if (a.after(b)) {
    return a;
return b;
Datemax(final Date a, final Date b)
max
if (a == null) {
    return b;
} else if (b == null) {
    return a;
return a.after(b) ? a : b;
Datemax(Set dateSet)
max
return (Date) new ArrayList(dateSet).stream().max(new Comparator<Date>() {
    @Override
    public int compare(Date o1, Date o2) {
        return o1.compareTo(o2);
}).get();
ListmergeNonDateKeys(List rowKeys, List columnKeys)
merge Non Date Keys
if (rowKeys.size() > 0) {
    List<String> result = new ArrayList<String>(rowKeys.size() + columnKeys.size());
    result.addAll(rowKeys);
    result.addAll(columnKeys);
    return result;
} else {
    return columnKeys;
Calendarmin(Calendar... dates)
Takes in a varargs of calendars and returns the one with the earliest date
Calendar least = null;
for (Calendar calendar : dates) {
    if (calendar != null) {
        if (least == null) {
            least = calendar;
        } else {
            if (calendar.before(least)) {
                least = calendar;
...