Objective c xcode NSDateFormatter在configureView内返回null

Objective c xcode NSDateFormatter在configureView内返回null,objective-c,nsdate,nsdateformatter,Objective C,Nsdate,Nsdateformatter,我正在尝试将NSDateFormatter与以下代码一起使用。这是my DetailViewController.m中的代码。我使用的是带有故事板和核心数据的Xcode 4.2。我在这里搜索了NSDateFormatter的其他主题,看起来我做得不错,但结果返回null - (void)configureView { // Update the user interface for the detail item. if (self.detailItem) {

我正在尝试将NSDateFormatter与以下代码一起使用。这是my DetailViewController.m中的代码。我使用的是带有故事板和核心数据的Xcode 4.2。我在这里搜索了NSDateFormatter的其他主题,看起来我做得不错,但结果返回null

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {

        // Format Date to MMM D, YYYY H:MM:SS AM/PM
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];

        NSString *sessDate = [[self.detailItem sessionDate] description];

        NSDate *date = [dateFormatter dateFromString:sessDate];
        NSString *formattedDate = [dateFormatter stringFromDate:date];

        self.sessionDate.text = formattedDate;

        NSLog(@"sessDate = %@",sessDate);
        NSLog(@"date = %@",date);
        NSLog(@"formattedDate = %@",formattedDate);
    }
}
NSLog结果:

2012-02-10 17:18:17.781 ClickIt[332:10103] sessDate = 2012-02-09 17:11:33 +0000
2012-02-10 17:18:17.782 ClickIt[332:10103] date = (null)
2012-02-10 17:18:17.782 ClickIt[332:10103] formattedDate = (null)
我以前使用过NSDateFormatter,它工作得很好,但我不明白为什么date变量返回null。有没有想过我做错了什么

谢谢


调整代码
我认为NSDateFormatTerminiumStyle对应于这样的东西——1937年11月23日。因此,您将获得空值

你能试试这个吗

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];

我认为NSDateFormatTerminiumStyle对应于这样的东西——1937年11月23日。因此,您将获得空值

你能试试这个吗

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];

你说得对,谢谢你!这个给我修好了。我重新整理了我的代码,现在它按照我想要的方式工作。你很正确,谢谢你!这个给我修好了。我重新整理了我的代码,现在它按照我想要的方式工作。pueden ayudarme con estan pregunta graciasI我正在尝试在这里使用相同的日期格式化程序,你能看一下吗?pueden ayudarme con estan pregunta graciasI我正在尝试在这里使用相同的日期格式化程序,你能看一下吗?