For example:
A user can enter 01/23/1983 or 1/23/1983
How would I use DateFormat to write up two different kinds of formats like (MM/DD/YYYY) and (M/DD/YYYY) and compare them to the actual date to see which one matches the date so I could parse it successfully?
Because Johan posted an incorrect solution, I feel obliged to post the correct one.
"MM/dd/yyyy"
will format both of your test Strings:A common solution when dealing with multiple input formats is to try a series of expected formats in a loop until one succeeds, or all fails. E.g.,