RFC822 date-string to NSDate
-
I'm having trouble grokking NSDateFormatter on OS X 10.4. Does it
support RFC822-style dates? I'm parsing an XML document; here's the
pertinent code snippet:
NSLog(@"observation_time_rfc822 element end");
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]
init];
[dateFormatter
setFormatterBehavior:NSDateFormatterBehavior10_4];
myObservationTime = [dateFormatter
dateFromString:myCurrentStringValue];
NSLog(@"myObservationTime %@", myObservationTime);
myObservationTimeRFC822 = [[NSString alloc]
initWithString:myCurrentStringValue];
The myObservationTimeRFC822 string is "Mon, 30 Jun 2008 13:56:00
-0400 EDT", but NSLog(@"myObservationTime %@", myObservationTime)
prints "myObservationTime 1969-12-31 19:00:00 -0500".
Best regards,
-Steve
--
Steve Byan <stevebyan...>
Littleton, MA 01460 -
I'm not too familiar with NSDateFormatter. Do you need to call -
setDateFormat:?
--Andy
On Jun 30, 2008, at 2:35 PM, Steve Byan wrote:
> I'm having trouble grokking NSDateFormatter on OS X 10.4. Does it
> support RFC822-style dates? I'm parsing an XML document; here's the
> pertinent code snippet:
>
> NSLog(@"observation_time_rfc822 element end");
> NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]
> init];
> [dateFormatter
> setFormatterBehavior:NSDateFormatterBehavior10_4];
> myObservationTime = [dateFormatter
> dateFromString:myCurrentStringValue];
> NSLog(@"myObservationTime %@", myObservationTime);
> myObservationTimeRFC822 = [[NSString alloc]
> initWithString:myCurrentStringValue];
>
> The myObservationTimeRFC822 string is "Mon, 30 Jun 2008 13:56:00
> -0400 EDT", but NSLog(@"myObservationTime %@", myObservationTime)
> prints "myObservationTime 1969-12-31 19:00:00 -0500".
>
> Best regards,
> -Steve
>
> --
> Steve Byan <stevebyan...>
> Littleton, MA 01460
-
On Jun 30, 2008, at 12:35 PM, Steve Byan wrote:
> I'm having trouble grokking NSDateFormatter on OS X 10.4. Does it
> support RFC822-style dates?
It should, but you'll have to make your own format string to do that.
NSDateFormatter does make some guesses at the format when getting the
date from a string, but only when it's using 10.0-style behavior, and
even then it's better to just make your own format string.
Nick Zitzmann
<http://www.chronosnet.com/> -
On Jun 30, 2008, at 2:50 PM, Andy Lee wrote:
> I'm not too familiar with NSDateFormatter. Do you need to call -
> setDateFormat:?
Ah, thanks, I missed the statement hidden on page 23 of "Data
Formatting Programming Guide for Cocoa", which says:
"You use the format string is used to specify both the input to and
the output from date formatter objects."
That's a bummer, because RFC822 dates have some optional elements and
so don't conform to a fixed format. I hoped that the default parsing
was smart.
Anyone have any pointers to some Objective-C RFC822-date-time parsing
code? An NSDateFormatter category containing
dateFromRFC822DateTimeString: would be great :-)
Best regards,
-Steve
--
Steve Byan <stevebyan...>
Littleton, MA 01460 -
On Mon, Jun 30, 2008 at 3:14 PM, Steve Byan <stevebyan...> wrote:
> That's a bummer, because RFC822 dates have some optional elements and so
> don't conform to a fixed format. I hoped that the default parsing was smart.
Well it looks like the RFC822 date grammar is context-free so
implementing a parser shouldn't be that hard. You'll have to deal
with Y2K, though.
--Kyle Sluder



