I surfed through existant questions regarding this theme, but my issue is little specific and i can’t figure out source of the problem.
I have string like:
str = @"Sun Mar 06 13:20:12 2011";
And i want to convert it to NSTimeInterval. Im doing it this way:
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"ddd mmm dd hh:mm:ss yyyy"];
NSDate *date = [formatter dateFromString:str];
NSTimeInterval interval = [date timeIntervalSince1970];
“date” always gets nil.
I think I’m wrongly defining the format, but can’t figure out at what part.
Based on http://www.deanoj.co.uk/ios-development/nsdateformatter-formatting-strings-reference/
you should use
ccc MMM dd hh:mm:ss yyyyinstead ofddd mmm dd hh:mm:ss yyyy