Using simpledateformat for unknown input date
in
Programming Questions
•
3 years ago
Hey,
I'd like to parse string dates from external files for use in one of my apps. I've gotten it working with simpledateformat, but as far as I can see, I need to specify the input format. As in:
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
My problem is that I'm not in control of the input date format, so I'm wondering if there is any way to check generically check for common formats, and see if one matches? In a similar way to excel interprets many formats.
- Is my only other option to iterate through a long list of possible formats (that I come up with) until one returns true?
- Alternatively, I suppose I could grep for certain 'date' characteristics (four digit number between 2000 and 2011, etc) to try to determine the format. Just seams like this is something that might already be implemented by someone much smarter than me.
- Third option would be to prompt user to give the date format, then parse on that.
Cheers,
RT
2