How to unify date format using DateTimeFormatter
问题 I need to parse different time format into BASIC_ISO_DATE . Right now, there are 4 types of date format: 2016-10-01 (ISO_LOCAL_DATE) 2016T 201610T 2016-02-07T22:03:39.937Z (ISO 8601) Need to parse to 20161001 and print out, with default day is 01 , default month Jan . Examples: 2016T -> 20160101 201610T -> 20161001 How can I use DateTimeFormatter to achieve this? 回答1: Just to complement @Flown's answer (which works perfectly BTW), you can also use optional patterns (delimited by [] ):