How to compare two string dates in Java?

后端 未结 8 1290
刺人心
刺人心 2020-12-15 22:41

I have two dates in String format like below -

String startDate = \"2014/09/12 00:00\";

String endDate = \"2014/09/13 00:00\";

I want to

8条回答
  •  天涯浪人
    2020-12-15 23:16

    Use SimpleDateFormat to convert to Date to compare:

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    Date start = sdf.parse(startDate);
    Date end = sdf.parse(endDate);
    System.out.println(start.before(end));
    

提交回复
热议问题