Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 错误的日期格式化程序?_Objective C - Fatal编程技术网

Objective c 错误的日期格式化程序?

Objective c 错误的日期格式化程序?,objective-c,Objective C,我有: 当日期字符串如图所示时,NSDate返回空值。用以下公式解决: //date Wed Sep 10 19:21:08 +0000 2014 NSString *date=[twt objectForKey:@"created_at"]; NSDateFormatter *df = [ [NSDateFormatter alloc] init] ; [df setDateFormat:@"EEE MMM d HH:mm:ss Z yyyy"]; NSDate *newdat

我有:

当日期字符串如图所示时,
NSDate
返回空值。

用以下公式解决:

//date
    Wed Sep 10 19:21:08 +0000 2014

NSString *date=[twt objectForKey:@"created_at"];
 NSDateFormatter *df = [ [NSDateFormatter alloc] init]  ;
 [df setDateFormat:@"EEE MMM d HH:mm:ss Z yyyy"];
NSDate *newdate = [df dateFromString:date];


 NSLog(@"%@",date); //good Wed Sep 10 21:13:46 +0000 2014
  NSLog(@"%@",newdate);// NULL

请看:我已经检查过了,不知道这里有什么问题。从twitter上我从字符串中得到了日期条和前导/尾随空格/换行符。奇怪的是,这正是我运行的代码,我得到了空值。套用Carly Simon的话:“你太虚荣了,你可能认为我否决了这个”-我没有。好吧,这是一个糟糕的否决票,应该有一个原因提供,以便它可以被纠正,或至少警告潜在用户的答案,因为你总是这样做,对吗?只有“坏人”才会投票否决一个好答案。
         NSString *date= [twt objectForKey:@"created_at"] ;
        NSDateFormatter *frm = [[NSDateFormatter alloc] init];
         [frm setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]  ];
          [frm setDateFormat:@"EEE MMM dd HH:mm:ss Z yyyy"];
          NSDate *newdate = [frm dateFromString:date ];