Generic way to parse dates in Java

后端 未结 7 849
醉酒成梦
醉酒成梦 2021-01-19 00:03

What is the best way to parse dates in Java ? Is there any built in way to parse strings such as \"18 Jul 2011\" , \"Jul 18, 2011\", \"18-07-2011\", \"2011-07-18\" without k

7条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 00:37

    If you are familiar with the Simpledateformat you can just add a couple of dateformatter in a list/array and do them all after another until one hits a valid date.

    The problem here is: What do you do with a date such as

    06-07-2011

    Is it July 6th or is it June 7th?

    But to answer to question: no there is not a "built in generic way"

提交回复
热议问题