There is no direct facility to do this, but you can use optional sections. Optional sections are enclosed inside squared brackets []
. This allows for the whole section of the String to parse to be missing.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("" + "[yyyy/MM/dd HH:mm:ss.SSSSSS]" + "[yyyy-MM-dd HH:mm:ss[.SSS]]" + "[ddMMMyyyy:HH:mm:ss.SSS[ Z]]" );
This formatter defines 3 grand optional sections for the three main patterns you have. Each of them is inside its own optional section.
Read full article from jodatime - Java 8 Date equivalent to Joda's DateTimeFormatterBuilder with multiple parser formats? - Stack Overflow
No comments:
Post a Comment