1
我從日期格式化程序獲取nil。 originTime
是2011-08-25 02:12:59,我相信yyyy-MM-dd HH:mm:ss
是正確的格式。我的錯誤是什麼?NSDate -dateFromString返回nil
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 timeZoneForSecondsFromGMT:0]];
NSDate *od = [dateFormat dateFromString:originTime]; // nil
[dateFormat setDateFormat:@「yyyy-MMM-dd HH:mm:ss」];試試這樣 –
沒有vijay的格式是正確的2行之後是問題 – Robin