Java Date Compare compareDate(String DATE1, String DATE2)

Here you can find the source of compareDate(String DATE1, String DATE2)

Description

compare Date

License

Open Source License

Parameter

Parameter Description

Exception

Parameter Description

Return

boolean

Declaration

public static boolean compareDate(String DATE1, String DATE2) 

Method Source Code


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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static boolean compareDate(String DATE1, String DATE2) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        boolean compareFlag = false;
        try {//from   w  ww. j  a v  a  2s.  c o m
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() > dt2.getTime()) {
                compareFlag = true;
            } else if (dt1.getTime() < dt2.getTime()) {
                compareFlag = false;
            } else {
                compareFlag = false;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return compareFlag;
    }
}

Related

  1. compareDate(String d1, String d2)
  2. compareDate(String d1, String d2)
  3. compareDate(String date)
  4. compareDate(String date0, String date1)
  5. compareDate(String date1, File file)
  6. compareDate(String date1, String date2)
  7. compareDate(String s, String e)
  8. compareDate(String s, String e)
  9. compareDate(String sDate, String eDate, String formatStr)