iphone - Parsing a RFC 822 date with NSDateFormatter -


I am using an NSDateFormatter to parse an RFC 822 date on the iPhone However, specify the optional element in the date format There is no way to do it. There are some optional parts in RFC 822 specification which are breaking the date parser, if nothing works, then I have to write a custom parser to follow the specs. For example, the name of the day in the imagery is optional. Therefore both dates are valid:

Tuesday, 01 December 2009 08:48:25 +0000 format is parsed with EEE, dd MMM yyyy HH: Mm: ss z December 00 08:48:25 +0000 format dd MMM yyyy HH: mm: ss z

Parsed with> This is what I am currently using:

  + (NSDateFormatter *) rfc822Formatter {static NSDateFormatter * formatter = noil; If (formatter == blue) {formatter = [[NSDateFormatter alloc] init]; NSLocale * enUS = [[NSLocale alloc] initWithLocaleIdentifier: @ "en_US"]; [Setter Sitelokel: NUS]; [Annus release]; [Format setDateFormat: @ "EEE, DD MMM yyyy HH: mm: SS Z"]; } Return formors; } + (NSDT *) Date FRMRFC 822: (NSSTING *) Date {NSDATFormat * Format = [NSDT RFC 822 Format]; Return [Format Date: FrameString: Date]; }  

and parsing date is as follows:

  self.entry.published = [NSDate dateFromRFC822: self.currentString];  

The only way is to try both formats, and whatever returns is to be considered non-blank, however, there are two alternate parts (day name and seconds) in space and 4 possible combinations Will be It's still not too bad, but it's a little bit hackneyed.

Before using the calculation of the number of main characters to use. For example, if you have two separate commas and spaces, if a known format matches the count, you can not even attempt to parse it as a date.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -