Compare Two String Date and Time in android?

前端 未结 9 705
北海茫月
北海茫月 2020-12-15 04:54

I have Two String Datetime as follows:

String Date1 = \"05-09-2013 10:46:10\"
String Date2 = \"06-09-2013 10:46:10\"

I Need to compare thes

9条回答
  •  别那么骄傲
    2020-12-15 05:07

    You can use following:

        public static boolean CheckDates(String startDate, String endDate) {
    
        SimpleDateFormat dfDate = new SimpleDateFormat("dd-MMM-yyyy");
    
        boolean b = false;
    
        try {
            if (dfDate.parse(startDate).before(dfDate.parse(endDate))) {
                b = true;  // If start date is before end date.
            } else if (dfDate.parse(startDate).equals(dfDate.parse(endDate))) {
                b = true;  // If two dates are equal.
            } else {
                b = false; // If start date is after the end date.
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    
        return b;
    }
    

提交回复
热议问题