Java Date Compare compare2DateString(String DateStringType, String dateStr1, String dateStr2)

Here you can find the source of compare2DateString(String DateStringType, String dateStr1, String dateStr2)

Description

compare Date String

License

Apache License

Declaration

public static int compare2DateString(String DateStringType, String dateStr1, String dateStr2) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

import java.text.SimpleDateFormat;

public class Main {

    public static int compare2DateString(String DateStringType, String dateStr1, String dateStr2) {
        try {// w  ww  .  jav a  2  s .  com
            SimpleDateFormat df = new SimpleDateFormat(DateStringType);
            Date d1 = df.parse(dateStr1);
            Date d2 = df.parse(dateStr2);

            if (d1.after(d2)) {
                return 0;
            } else if (d1.equals(d2)) {
                return 1;
            } else {
                return 2;
            }
        } catch (Exception e) {
            return -1;
        }
    }
}

Related

  1. compare(Date startDate, Date endDate, Date targetDate)
  2. compare(final Date lhs, final Date rhs)
  3. compare(final Date one, final Date another)
  4. compare2Date(Date date1, Date date2)
  5. compare2Dates(Date d1, Date d2)
  6. compare_date2(String finalDate, String enddate)
  7. compareCalendars(Date fechaAComparar, Date fechaBase)
  8. compareDate(Date d1, Date d2)
  9. compareDate(Date d1, Date d2)