I am trying to parse the following date: May 5 18:44:44
from a syslog entry. Note that after 'May' there are 2 spaces: one as separator and the other as omitted zero from the day of month.
The following code fails with java.lang.IllegalArgumentException: Invalid format: "May 5 18:44:44" is malformed at " 5 18:44:44"
String input = "May 5 18:44:44";
DateTimeFormatter formatter = DateTimeFormat.forPattern("MMM d HH:mm:ss")
.withLocale(Locale.US);
DateTime dt = formatter.parseDateTime(input);
Apparently the parser does not grok the 2nd space. And it also works when I "manually" remove that 2nd space.
Does anyone have an idea on how to solve this either with joda time or standard java DateFormat
?