In dealing with a wide variety of JSON data being sent from various clients date format standardization is a real problem.
I might get any of these:
2013-10-05
2-6-13
Mon, Jul 13 2013
Sometimes there's hours, minutes and seconds as well as time zone information. For each client I've had to manually set up an NSDateFormatter
, or if unable to get it parsing I've done substring searching. What I'd really like to do is get all this combined into a single method and somehow determine which type I'm dealing with. Then have some kind of switch statement that handles the parsing for that particular date.
I'm unable to change their formats, but how can I deal with them better?
This is not exactly the answer to your question but when I'm looking to parse dates without being sure of the format I usually go for NSDataDetector setup for dates only. The detector will often detect dates in multiple languages and format all at once. It's pretty neat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With