Manuel Spuhler’s second manual analysis tip is not my favorite option, but the Objective-C options are too complicated for this (and there aren’t enough error messages - something isn’t so easy to spit nil
without an error message).
One thing that worked for me was to use C strptime
to separate the date and then restore it as an NSDate
object. For example, the code below transfers the string received as “Monday, 28-Sep-09 18:13:50 UTC” and converts it to an NSDate object, adapting the UTC time to local time:
struct tm time; strptime([currentStringValue UTF8String], "%A, %d-%b-%y %H:%M:%S %z", &time); NSDate* myDate = [NSDate dateWithString: [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d +0000", time.tm_year+1900, time.tm_mon+1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec] ];
(can handle other zones by adding other parameters to struct tm
instead of the fixed time zone +0000, see time.h entry in wikipedia for more information):
source share