Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine which date format I've received?

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?

like image 860
DC2 Avatar asked Nov 12 '22 01:11

DC2


1 Answers

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.

like image 200
aLevelOfIndirection Avatar answered Dec 10 '22 21:12

aLevelOfIndirection