Java 8 Variable Day Time

I can't seem to get my date with a variable space for parsing.

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss yyyy"); LocalDateTime dateTime = LocalDateTime.parse(date, formatter); 

This is the format I have to accept.

 Sat Jul 2 08:52:13 2016 Sat Jul 12 08:52:13 2016 

I can get the top if I change my formatter below, but it breaks with a two digit number

 EEE MMM d HH:mm:ss yyyy 
+6
source share
1 answer

You can try the sample "EEE MMM ppd HH: mm: ss yyyy" for your format.

ppd displays the daily space on the left with spaces up to a width of 2.

See the Pad modifier in DateTimeFormatter for more details.

+6
source

All Articles