以下方法得到的createDate为nil
NSDateFormatter*formatter = [[NSDateFormatteralloc]init];
//格式Thu May 05 10:04:37
+0800 2016
[formattersetDateFormat:@"EEE MMM dd
HH:mm:ss zzz yyyy"];
NSDate*createDate =
[formatterdateFromString:@"Thu May 05 10:04:37 +0800
2016"];
正确方式:
NSDateFormatter*formatter = [[NSDateFormatteralloc]init];
//格式Thu May 05 10:04:37
+0800 2016
[formattersetDateFormat:@"EEE MMM dd
HH:mm:ss zzz yyyy"];
formatter.locale= [[NSLocalealloc]initWithLocaleIdentifier:@"en_US"];
NSDate*createDate =
[formatterdateFromString:@"Thu May 05 10:04:37 +0800
2016"];
网友评论