Java Date Compare compareDate(Date date1, Date date2, String pattern)

Here you can find the source of compareDate(Date date1, Date date2, String pattern)

Description

compare Date

License

Open Source License

Declaration

public static int compareDate(Date date1, Date date2, String pattern) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    public static int compareDate(Date date1, Date date2, String pattern) {
        String d1 = date2Str(date1, pattern);
        String d2 = date2Str(date2, pattern);
        return d1.compareTo(d2);
    }/*from ww  w.  ja v a2  s . co  m*/

    public static String date2Str(Date date, String pattern) {
        if (null == date) {
            return null;
        }
        if (null == pattern) {
            pattern = DEFAULT_DATE_FORMAT;
        }
        SimpleDateFormat format = new SimpleDateFormat();
        format.applyPattern(pattern);
        return format.format(date);
    }
}

Related

  1. compareDate(Date date1, Date date2)
  2. compareDate(Date DATE1, Date DATE2)
  3. compareDate(Date date1, Date date2)
  4. compareDate(Date date1, Date date2)
  5. compareDate(Date date1, Date date2)
  6. compareDate(Date first, Date second)
  7. compareDate(Date sourceDate, Date targetDate)
  8. compareDate(Date start, Date end)
  9. compareDate(String begingDate, String endDate, String format)