views:

30

answers:

1

I need to parse following string into NSDate.

Example: 2008-09-28T02:48:16+05:30

I tried following but it is not working

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSLog(@"Date=%@",[dateFormatter dateFromString:@"2008-09-28T02:48:16+05:30"]);

It works only if I keep the @"2008-09-28T02:48:16+05:30" to @"2008-09-28T02:48:16+0530".

A: 

As far as I know it cannot be done. If you put ZZZZ for example you get "GMT+09:00".

Easiest would be just to remove the colon from the input string.

NSMutableString *input = [[NSMutableString alloc] initWithString:@"2008-09-28T02:48:16+05:30"];
[input replaceCharactersInRange:NSMakeRange(input.length-3, 1) withString:@""];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSLog(@"Date=%@",[dateFormatter dateFromString:input]);
[input release];
vakio
Thanks for the solution, but that is what i am doing right now. My only concern is to know whether it is possible or not without remove colon from timezone section. it may be some date format which can able to parse my given date string properly.FYI, currently i am using 10.5 SDK. It might be possible that there is some solution for this in 10.6 SDK or some third party date parsing code.
AmitSri