Why my NSDateFormatter returns null?
Here is my code:
NSString *dateString = @"21-12-2012 11:05:15";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy hh:mm:ss"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
NSString *strDate = [dateFormatter stringFromDate:dateFromString];
My strDate
returns
21/12/2012
but when:
NSString *dateString = @"13-12-2012 13:17:58";
My strDate
returns null
This is very weird, anyone has experienced the same?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…