Re: NSDate / NSXMLParser
Re: NSDate / NSXMLParser
- Subject: Re: NSDate / NSXMLParser
- From: David Rowland <email@hidden>
- Date: Tue, 3 Nov 2009 12:15:01 -0800
On Nov 3, 2009, at 10:37 AM, Nick Zitzmann wrote:
On Nov 3, 2009, at 9:26 AM, David Rowland wrote:
No doubt my inexperience with the parser or NSDate is at fault. How
do I get the parser to recognize that the time really is UTC?
If you're using NSDateFormatter, you set the time zone by setting
the formatter's calendar with an NSCalendar with the desired
NSTimeZone.
Here is code from SeismicXML which I modified by adding the four lines
in the middle,
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]
autorelease];
NSTimeZone* UTCZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSCalendar* theCalendar = [dateFormatter calendar];
[theCalendar setTimeZone:UTCZone];
[dateFormatter setCalendar:theCalendar];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
self.currentEarthquakeObject.date =
[dateFormatterdateFromString:self.currentParsedCharacterData];
It still gets the hours right but tags the time zone as -0800 (Pacific).
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden