Java Date Compare compareDate(String startDate, String endDate, String strFormat)

Here you can find the source of compareDate(String startDate, String endDate, String strFormat)

Description

compare Date

License

Open Source License

Declaration

public static int compareDate(String startDate, String endDate, String strFormat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;

import java.util.*;

public class Main {

    public static int compareDate(String startDate, String endDate, String strFormat) {
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(strFormat);

        Calendar start = Calendar.getInstance();
        Date tempstartdate;/*from  ww  w  .  j a v  a 2  s.  co m*/
        Calendar end = null;
        try {
            tempstartdate = formatter.parse(startDate);
            start.setTime(tempstartdate);

            end = Calendar.getInstance();
            Date tempenddate = formatter.parse(endDate);
            end.setTime(tempenddate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if (start.before(end)) {
            return -1;
        } else if (start.after(end)) {
            return 1;
        } else {
            return 0;
        }
    }
}

Related

  1. compareDate(String s, String e)
  2. compareDate(String s, String e)
  3. compareDate(String sDate, String eDate, String formatStr)
  4. compareDate(String sFirstDate, String sSecondDate)
  5. compareDate(String startdate, String enddate)
  6. compareDate(String strDate1, String strDate2, String format)
  7. compareDate2(String begingDate, String endDate, String format)
  8. compareDateFormat(String strDate1, String strDate2, String format)
  9. compareDateForSecond(Date src, Date target, int second)