views:

1429

answers:

1

Good day,

i have an NSDateFormatter that doesn't seem to like a particular string that i am trying to convert. this particular instance is

2009-10-16T09:42:24.999605

All of my other dates are formatted the same, and can be parsed.

Here is the code that converts the string in the NSDate.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSS"];

[order setModifiedAtDate:[dateFormatter dateFromString:[orderDataDictionary valueForKey:@"ModifiedAt"]]];

order.ModifiedAtDate is nil after the dateFromString call.

Has anyone else come across cases where their dates could not converted into NSDates?

Thanks,

+2  A: 

I was able to get the date to parse by removing the subsecond field from the formatter:

NSString *test = @"2009-10-16T09:42:24.999605";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSDate *testOut = [dateFormatter dateFromString:test];

I suspect you can find out in greater detail why it failed with the subsecond field using this function as it looks like it does the same thing, but returns error messages:

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter%5FClass/Reference/Reference.html#//apple%5Fref/occ/instm/NSDateFormatter/getObjectValue%3AforString%3Arange%3Aerror:

At any rate, hopefully this gets you going again.

Epsilon Prime