Java Date Format that allows - / or . as separators within date

Tarski picture Tarski · Sep 18, 2009 · Viewed 7k times · Source

What's the nicest way to parse a date that can be in one of the following formats

 "dd-MM-yyyy HH:mm"
 "dd/MM/yyyy HH:mm"
 "dd.MM.yyyy HH:mm"

without creating 3 SimpleDateFormats and parsing against each one.

Thanks

Answer

kgiannakakis picture kgiannakakis · Sep 18, 2009

Could you run two replace operations first, so that you reduce all three formats to a single one?