Java Date Compare compareDate2(String begingDate, String endDate, String format)

Here you can find the source of compareDate2(String begingDate, String endDate, String format)

Description

compare Date

License

Open Source License

Declaration

public static boolean compareDate2(String begingDate, String endDate, String format) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;
import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static boolean compareDate2(String begingDate, String endDate, String format) {
        boolean boo = true;
        Date begin = null;//from  www .  j  a  v a 2 s . c o m
        Date end = null;
        if (format.isEmpty()) {
            format = format = "yyyy/MM/dd";
        }
        // if(begingDate.indexOf("-") != -1) {
        // format = "yyyy-MM-dd";
        // }
        // if(endDate.indexOf("-") != -1) {
        // format = "yyyy-MM-dd";
        // }
        DateFormat df = new SimpleDateFormat(format);
        if (null == begingDate || "".equals(begingDate)) {
            boo = false;
            return boo;
        }
        if (null == endDate || "".equals(endDate)) {
            boo = false;
            return boo;
        }
        try {
            begin = df.parse(begingDate);
            end = df.parse(endDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (begin.compareTo(end) > 0) {
            boo = false;
        }
        return boo;
    }

    public static String parse(Date d) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
        String dateStr = sdf.format(d);
        return dateStr;
    }
}

Related

  1. compareDate(String sDate, String eDate, String formatStr)
  2. compareDate(String sFirstDate, String sSecondDate)
  3. compareDate(String startdate, String enddate)
  4. compareDate(String startDate, String endDate, String strFormat)
  5. compareDate(String strDate1, String strDate2, String format)
  6. compareDateFormat(String strDate1, String strDate2, String format)
  7. compareDateForSecond(Date src, Date target, int second)
  8. compareDates(Date date1, Date date2)
  9. compareDates(Date date1, Date date2)