Parse any date in Java

后端 未结 6 792
时光取名叫无心
时光取名叫无心 2020-11-22 07:31

I know this question is asked quite a bit, and obviously you can\'t parse any arbitrary date. However, I find that the python-dateutil library is able to parse every date I

6条回答
  •  温柔的废话
    2020-11-22 08:03

    What I have seen done is a Date util class that contains several typical date formats. So, when DateUtil.parse(date) is called, it tries to parse the date with each date format internally and only throws exceptions if none of the internal formats can parse it.

    It is basically a brute force approach to your problem.

提交回复
热议问题