I am getting nil from the date formatter. originTime
is 2011-08-25 02:12:59, and I believe yyyy-MM-dd HH:mm:ss
is the correct format for that. What is my mistake?
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
assert(locale != nil);
[dateFormat setLocale:locale];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormat setDateStyle:NSDateFormatterLongStyle];
[dateFormat setTimeStyle:NSDateFormatterShortStyle];
[dateFormat setTimeZone:[NSTimeZone ti开发者_JAVA百科meZoneForSecondsFromGMT:0]];
NSDate *od = [dateFormat dateFromString:originTime]; // nil
Just delete the setDateStyle
and setTimeStyle
methods. You are specifying the format on your own (with setDateFormat
).
精彩评论