I have a string that contains a .net datetime (rawData) and I am trying to parse it into a NSDate
object using a NSDateFormatter
. I think my format string might be wrong or something because the dateFromString:
method is returning nil. Can any one please help me figure out the issue here?
NSString *rawData = @"2009-10-20T06:01:00-07:00";
//Strip the colon out of the time zone
NSRange timezone = NSMakeRange([data length] - 3, 3);
NSString *cleanData = [rawData stringByReplacingOccurrencesOfString:@":" withString:@"" options:NSCaseInsensitiveSearch range:timezone ];
//Setup a formatter and parse it into a NSDate object
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-ddThh:mm:ssZ"];
NSDate *result = [df dateFromString: cleanData]; //Result is nil