Parsing Ambiguous Dates in Java

后端 未结 4 1027
谎友^
谎友^ 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:12

    My recommendation is don't. Use a date picker or an explicitely noted format. Guessing will lead to all kinds of problems, easily including, if the date is a critical one, litigation.

    If you have to guess, provide some form of feedback that is non-ambiguous, something like a confirmation page that says "Your flight will be booked on the 9th of November, 2009. Is this correct?".

提交回复
热议问题