Java - How to check if a value is of type Date

后端 未结 6 774
耶瑟儿~
耶瑟儿~ 2021-01-29 09:22

I have a project requirement. There are values in a .txt as -

 02/01/2017 00:00:00

Now I need to have some rules to check if this value in the

6条回答
  •  情书的邮戳
    2021-01-29 10:10

    Try to parse it to date. If it throws ParseException then it is not a date.

    String dateString = "02/01/2017 00:00:00";
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss"); 
    Date date;
    try {
        date = df.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题