Java Date Compare compareDate(String sDate, String eDate, String formatStr)

Here you can find the source of compareDate(String sDate, String eDate, String formatStr)

Description

compare Date

License

Open Source License

Declaration

public static int compareDate(String sDate, String eDate, String formatStr) 

Method Source Code


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

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

public class Main {

    public static int compareDate(Date sDate, Date eDate) {
        Calendar sC = Calendar.getInstance();
        sC.setTime(sDate);//from w w  w.j a va  2 s  .  co m
        Calendar eC = Calendar.getInstance();
        eC.setTime(eDate);
        return sC.compareTo(eC);
    }

    public static int compareDate(String sDate, String eDate, String formatStr) {
        Date startDate = strToDate(sDate, formatStr);
        Date endDate = strToDate(eDate, formatStr);
        return compareDate(startDate, endDate);
    }

    public static Date strToDate(String dateStr, String formatStr) {
        Date date = null;
        try {
            SimpleDateFormat format = new SimpleDateFormat(formatStr);
            date = format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. compareDate(String date1, File file)
  2. compareDate(String date1, String date2)
  3. compareDate(String DATE1, String DATE2)
  4. compareDate(String s, String e)
  5. compareDate(String s, String e)
  6. compareDate(String sFirstDate, String sSecondDate)
  7. compareDate(String startdate, String enddate)
  8. compareDate(String startDate, String endDate, String strFormat)
  9. compareDate(String strDate1, String strDate2, String format)