Parsing Ambiguous Dates in Java

后端 未结 4 1031
谎友^
谎友^ 2020-12-19 23:31

Is there any way in Java to guess the date format when it is not explicitly defined?

For example a user types in 11Mar09 or 11-09-2009 or 11/09/2009 or 11-09 what is

4条回答
  •  忘掉有多难
    2020-12-20 00:32

    As the domain of possible date-strings are infinite, I don't see how it could be possible to recognize them all. You can however pick a subset for pattern-matching.

    You give no clues about your user-interface, but the best approach here would be to help the user input the date. For example with a pop-up calendar or just forcing a predefined format.

提交回复
热议问题