Java Second Compare compareDate(Date firstDate, Date secondDate)

Here you can find the source of compareDate(Date firstDate, Date secondDate)

Description

compare Date

License

Open Source License

Declaration

public static boolean compareDate(Date firstDate, Date secondDate) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String PATTERN_STANDARD = "yyyy-MM-dd HH:mm:ss";

    public static boolean compareDate(Date firstDate, Date secondDate) {
        if (firstDate == null || secondDate == null) {
            throw new java.lang.RuntimeException();
        }// w w  w.j  a  v a  2  s  .  c  om

        String strFirstDate = date2String(firstDate, "yyyy-MM-dd");
        String strSecondDate = date2String(secondDate, "yyyy-MM-dd");
        if (strFirstDate.equals(strSecondDate)) {
            return true;
        }
        return false;
    }

    public static String date2String(java.util.Date date, String pattern) {
        if (date == null) {
            throw new java.lang.IllegalArgumentException("timestamp null illegal");
        }
        if (pattern == null || pattern.equals("")) {
            pattern = PATTERN_STANDARD;
            ;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
}

Related

  1. compareIgnoreSecond(Date date, Date anotherDate)
  2. getSecondBetweenDate(Date d1, Date d2)
  3. getSecondCa(Date d1, Date d2)
  4. getSecondsOfTowDiffDate(String p_startDate, String p_endDate)