Java Date Compare getCompareResult(String date1, String date2)

Here you can find the source of getCompareResult(String date1, String date2)

Description

get Compare Result

License

Open Source License

Declaration

public static boolean getCompareResult(String date1, String date2) 

Method Source Code

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

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static boolean getCompareResult(String date1, String date2) {
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(strToDate(date1));
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(strToDate(date2));
        if (calendar2.after(calendar1)) {
            return true;
        }// w  ww .  j a va  2 s  . c  o  m
        return false;
    }

    public static Date strToDate(String strDate) {
        return strToDate(strDate, "yyyy-MM-dd");
    }

    public static Date strToDate(String strDate, String format) {
        if (strDate == null) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }
}

Related

  1. compDate4(Date date1, Date date2)
  2. getCompareDate(Date startDate, Date endDate)
  3. getCompareDate(String strDate1, String strDate2, String pFormat)
  4. getCompareDate(String strDate1, String strDate2, String pFormat)
  5. getCompareDateNum(String sDateValue1, String sDateValue2)
  6. isAfterOrEqual(Date date, Date toCompare)
  7. isBeforeDate(String sCompareDate)
  8. isInDate(Date date, Date compareDate)
  9. max(Collection datumok)