Unparsable date exception

前端 未结 5 1220
我在风中等你
我在风中等你 2021-01-21 21:37

I\'m currently working on some simple project in Java and I have date in the following string:

String dateString = \"Sun 7/14 03:44 AM 2013\";
         


        
5条回答
  •  Happy的楠姐
    2021-01-21 21:56

    The modern answer for the sake of completeness. While the other answers were good answers in 2013, Date, DateFormat and SimpleDateFormat are now long outdated, and I recommend you replace them with their modern counterparts:

        DateTimeFormatter parser 
                = DateTimeFormatter.ofPattern("EEE M/dd hh:mm a yyyy", Locale.ENGLISH);
        LocalDateTime ldt = LocalDateTime.parse(dateString, parser);
    

    The result is a LocalDateTime of 2013-07-14T03:44 as expected.

    The format pattern string is still the same, and the need for an English language locale is the same.

提交回复
热议问题