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,
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_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDateFormatter/getObjectValue:forString:range:error:
At any rate, hopefully this gets you going again.
You should try lowercase "s" in decimals place, like this:
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.ssssss"]
It worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With