Date parser for all formats
I have date formats like this which I want to parse --
02 September 2011 15:57
Friday, September 02, 2011 9:51 AM
Mittwoch, 10. August 2011 开发者_StackOverflow社区16:31
woensdag 10 augustus 2011 14:09
Wed, 27 Jul 2011 20:23:18 -0000 (UTC)
Can we have any parser which can do this also considering the language difference?
Regards Neha
Defining a universal date parser is not possible due to ambiguities in date formats. For example:
12/11/2011
... implies November 12th 2011 using the UK date convention but December 11th 2011 using the US convention.
You could take an approach where you define a List
of SimpleDateFormat
classes, each specifying a date pattern and attempt to parse the dates in that order. However, I wouldn't personally recommend it as it will result in unintuitive behaviour for any end users (assuming there are any) and / or difficult-to-track-down data related bugs. Far better to either define an explicit date format or rely on the system locale settings (depending on your problem domain).
精彩评论