strptime_l is always returning null. I’m doing this in Objective-C.
#import <time.h>
#import <xlocale.h>
/* Later on... */
const char *str = [dateStr UTF8String];
const char *fmt = [@"EE LLLL d HH:mm:ss Z yyyy" UTF8String];
struct tm timeinfo;
memset(&timeinfo, 0, sizeof(timeinfo));
char *ret = strptime_l(str, fmt, &timeinfo, NULL);
NSDate *date = nil;
if (ret) {
time_t time = mktime(&timeinfo);
date = [NSDate dateWithTimeIntervalSince1970:time];
}
ret is always null. An example of dateStr‘s value is: Sat Sep 15 05:52:10 +0000 2012 and is always in that format.
Any ideas?
You seem to be using the NSDateFormatter format instead of the strptime one. Take a look here for more info its specific date and time format.
The following code should work:
By the way you could have achieved the same by simply doing: