Could someone show me the best way to parse the first occurrence of dates (could be in different date formats, MM/dd/yy, yyyy/MM/dd, etc.) in a string preferably without using regular expression? Thank you.
Raj S Kumar
Ranch Hand
Joined: Aug 06, 2006
Posts: 48
posted
0
Hi Thomas,
Posting some sample strings would help us understand the problem better.
Use a List or array of DateFormats with the formats you will allow. Loop over them, use DateFormat.parse(String, ParsePosition) checking the return value against non-null.
Raj S Kumar wrote:Hi Thomas,
Posting some sample strings would help us understand the problem better.
Hi Raj,
It's just any text String with some form of date (in more than one possible formats) in it. The goal is to parse this date (in all possible formats) and print out the first occurrence. I hope I made myself clear. Thanks for reading.