views:

205

answers:

3

I have an iPhone app. that is receiving data with IRFC 3339 timestamp format (e.g. @"2010-01-29T11:30:00.000+01:00"), as in GData. I want to convert the data to an NSDate

NSDateFormatter *inputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[inputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
[currentEntry setStartTime:[inputFormatter dateFromString: ][currentEntry startTimeString]]];

But I'm missing out how to convert the last part of the string @"2010-01-29T11:30:00.000+01:00": the time offset. Anyone knows what I have to add to this String to take the time offset in account too?

+1  A: 

I believe "Z" in the format string specifies the timezone offset

David Gelhar
You mean I just have to add a Z to @"yyyy-MM-dd'T'HH:mm:ss.SSS" like @"yyyy-MM-dd'T'HH:mm:ss.SSSZ"?
Olivier de Jonge
You are correct. http://unicode.org/reports/tr35/tr35-6.html#Date_Format_PatternsNote with GData, iirc, for zulu time they use Z instead of -00:00, so you may have to deal with that issue also.
Brandon Bodnár
Yes, that's it exactly.
David Gelhar
A: 

If you are doing a lot with GData, I also recommand using google's objective-c client code, they provided classes to help in creating standard Objective-C objects from the GData.

Brandon Bodnár
Thanks for the tip!
Olivier de Jonge
A: 

You will need to strip out the colon and add "ZZZ" to the format string. This parses time zone offsets like "+100" or "-500".

Jason
It works fine with only one "Z"
Olivier de Jonge