Java Date Compare compare(Date date1, Date date2, String format)

Here you can find the source of compare(Date date1, Date date2, String format)

Description

compare

License

Open Source License

Declaration

public static int compare(Date date1, Date date2, String format) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static int compare(Date date1, Date date2, String format) {
        if (date1 == null && date2 == null) {
            return 0;
        }//from w  w  w.  j a  va 2  s .c  o m
        if (date1 == null) {
            return -1;
        }
        if (date2 == null) {
            return 1;
        }

        String strDate1 = format(date1, format);
        String strDate2 = format(date2, format);

        return strDate1.compareTo(strDate2);
    }

    public static String format(Date date, String format) {
        return date != null ? new SimpleDateFormat(format).format(date).toString() : "";
    }
}

Related

  1. after(String format, String baseDate, String compareDate)
  2. compare(Date d1, Date d2)
  3. compare(Date d1, Date d2)
  4. compare(Date d1, Date d2)
  5. compare(Date date, Date fromDate, Date toDate)
  6. Compare(Date dtA, Date dtB, boolean bUnkIsPast)
  7. compare(Date start, Date end)
  8. compare(Date start, String end)
  9. compare(Date startDate, Date endDate, Date targetDate)