Compare Two String Date and Time in android?

前端 未结 9 682
北海茫月
北海茫月 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:06

    try{
    
         SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    
    
         String str1 = "12/10/2013";
         Date date1 = formatter.parse(str1);
    
         String str2 = "13/10/2013";
         Date date2 = formatter.parse(str2);
    
         if (date1.compareTo(date2)<0)
          {
             System.out.println("date2 is Greater than my date1");                         
          }
    
        }catch (ParseException e1){
            e1.printStackTrace();
        }
    

提交回复
热议问题