Java Date Compare compareDate(String s, String e)

Here you can find the source of compareDate(String s, String e)

Description

compare Date

License

Open Source License

Parameter

Parameter Description
s a parameter
e a parameter

Declaration

public static boolean compareDate(String s, String e) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Main {
    private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final Lock LOCK = new ReentrantLock();

    public static boolean compareDate(String s, String e) {
        if (parseDate(s) == null || parseDate(e) == null) {
            return false;
        }/*ww w  . j  a  va2  s .c  om*/
        return parseDate(s).getTime() >= parseDate(e).getTime();
    }

    public static Date parseDate(String date) {
        return parseDate(date, "yyyy-MM-dd");

    }

    public static Date parseDate(String date, String pattern) {

        LOCK.lock();
        try {
            DateFormat fmt = new SimpleDateFormat(pattern);
            return fmt.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        } finally {
            LOCK.unlock();
        }
    }

    public static String getTime() {
        return sdfTime.format(new Date());
    }
}

Related

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