String上的Java java.time.format.DateTimeParseException

Béa*_*nac 0 java

我正在尝试解析日期以将其转换为时代.我在这里尝试了类似问题的解决方案但没有成功:

String date = "Jun 4 2015";    
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("LLL dd yyyy").withLocale(Locale.ENGLISH);
LocalDateTime ldt  = LocalDateTime.parse(date, formatter);
System.out.println(date+" "+ldt.toEpochSecond(ZoneOffset.UTC));
Run Code Online (Sandbox Code Playgroud)

Exception in thread "main" java.time.format.DateTimeParseException: Text 'Jun 4 2015' could not be parsed at index 0即使我相当肯定我的正则表达式是正确的,我也会得到.我在这里错过了什么?

编辑:

在评论之后,我将LocalDateTime更改为LocalDate,但不断收到相同的错误:

String date = "Jun 4 2015";    
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy").withLocale(Locale.ENGLISH);
LocalDate ldt  = LocalDate.parse(date, formatter);
Run Code Online (Sandbox Code Playgroud)

std*_*bar 6

    String date = "Jun 4 2015";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy").withLocale(Locale.ENGLISH);
    LocalDate ldt  = LocalDate.parse(date, formatter);
Run Code Online (Sandbox Code Playgroud)

解析得很好.不要把"DD",因为它不会解析超过10天少作为@JB Nizet说,你需要使用LOCALDATE的,不LocalDateTime.