Parsing date with a possible one-bit month / day / hour using java.text.SimpleDateFormat

In a project with Talend Open Studio (an ETL tool that generates open source code), I get errors parsing incoming date strings like "3/14/1967 0:00:00" (note the one-month month).

Digging into the code , I see this uses java.text.SimpleDateFormat . So the date template string I expect I need to use is "dM-yyyy H: mm: ss" ... but it continues to give me errors like "Unmatched date: 3/14/1967 0: 00:00 ".

I guess SimpleDateFormat might be dealing with a one or two digit problem. Do I need a different date template? (Of course, I could do the preprocessing to adjust the values ​​before Java tries to read the lines as Dates, but this is not necessary!)

+3
source share
1 answer

Are you sure you want to use dM-yyyy , not M/d/yyyy ? I can understand why he would have a problem with "3/14/1967" ... what date did you expect? Please note that you not only received "d" and "M", but also indicated "-" instead of "/" as the delimiter.

+6
source

Source: https://habr.com/ru/post/911377/


All Articles