Java Date Compare compareDateFormat(String strDate1, String strDate2, String format)

Here you can find the source of compareDateFormat(String strDate1, String strDate2, String format)

Description

compare Date Format

License

Open Source License

Declaration

public static boolean compareDateFormat(String strDate1, String strDate2, String format) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static boolean compareDateFormat(String strDate1, String strDate2, String format) {
        Date date1 = convertStrToDate(strDate1, format);
        Date date2 = convertStrToDate(strDate2, format);
        if (date1.getTime() > date2.getTime()) {
            return true;
        }/*from   www  . jav a 2 s  . c o m*/
        return false;
    }

    public static Date convertStrToDate(String s) {
        try {
            DateFormat dateformat = DateFormat.getDateInstance();
            Date date = dateformat.parse(s);
            return date;
        } catch (Exception exception) {
            exception.printStackTrace();
            Calendar cal = Calendar.getInstance();
            cal.set(1900, 0, 1);
            return cal.getTime();
        }
    }

    public static Date convertStrToDate(String s, String format) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(format);
        try {
            Date date = simpledateformat.parse(s);
            return date;
        } catch (Exception exception) {
            exception.printStackTrace();
            Calendar cal = Calendar.getInstance();
            cal.set(1900, 0, 1);
            return cal.getTime();
        }
    }
}

Related

  1. compareDate(String sFirstDate, String sSecondDate)
  2. compareDate(String startdate, String enddate)
  3. compareDate(String startDate, String endDate, String strFormat)
  4. compareDate(String strDate1, String strDate2, String format)
  5. compareDate2(String begingDate, String endDate, String format)
  6. compareDateForSecond(Date src, Date target, int second)
  7. compareDates(Date date1, Date date2)
  8. compareDates(Date date1, Date date2)
  9. compareDates(final Date dateA, final Date dateB)