1

I have to parse a string that can contain date in any format. Currently I have set a list of predefined formats like this:

List<String> dateFormatsList =["MMddyy",'MM/dd/yyyy', 'MM-dd-yyyy',"MMM-yyyy","MMM-yy","MMMM-yy"] ;

Each format is tried on a given input string like this: result = DateFormat(format).parse(str_input);

But there can be many more date formats than those in the list.

Therefore I am trying to think of a way to parse a date in any format with specify a list of predefined formats.

Feel free to share if you have any ideas.

Thanks

JustCode
  • 463
  • 2
  • 11
Leo
  • 436
  • 1
  • 3
  • 14
  • You've asked very similar questions in the past ([1](https://stackoverflow.com/q/72059158/), [2](https://stackoverflow.com/q/71970859/)). How is this question different? – jamesdlin Apr 30 '23 at 16:04
  • Let me share the differences – Leo Apr 30 '23 at 16:20
  • 3
    Oh, I think you mean "I am trying to think of a way... with**out** ... a list of predefined formats." Some dates will be inherently ambiguous. You cannot tell what "01-02-03", "01-02-2023", "012023", etc. are meant to represent. – jamesdlin Apr 30 '23 at 16:29
  • Thats true I am trying to think of a way... without ... a list of predefined formats – Leo Apr 30 '23 at 20:25

0 Answers0