gpt4 book ai didi

xcode - NSDateFormatter 在三次使用中的第三次返回 NULL

转载 作者:行者123 更新时间:2023-12-03 17:58:02 27 4
gpt4 key购买 nike

好吧,这个让我感到困惑,我希望一些新的视角可以引导我在这里得出正确的结论...我在尝试使用它的第三个项目上从 NSDateFormatter 返回了 NULL我似乎不明白为什么。这是我的代码:

NSDateFormatter *format = [[NSDateFormatter alloc] init];
NSDate *tempDate;

[format setDateFormat:@"MMM dd, yyyy"];
tempDate = [format dateFromString:[activePerformance performanceDate]];
[outletPerformanceDate setDateValue:tempDate];

// display performance time and set length

[format setDateFormat:@"hh:mm a"];
tempDate = [format dateFromString:[activePerformance performanceTime]];
[outletPerformanceTime setDateValue:tempDate];

这两者都可以正常工作并按预期工作。然后,还有这个:

[format setDateFormat:@"MMM dd yyyy"];
tempDate = [format dateFromString:[activeFan birthday]];
[outletFansBirthday setDateValue:tempDate];

每次都会向 tempDate 返回 NULL。运行 NSLogs,我们可以看到 [activeFanbirthday] 设置为“1980 年 5 月 2 日”或放入变量中的任何日期。由于这不起作用,我将其更改为这样进行测试:

[format setDateFormat:@"MMM dd yyyy"];
tempDate = [format dateFromString:@"Jan 22, 1976"]; // TESTING

每次仍然返回NULL。

我认为这些代码行之间可能发生了一些事情(它们不是直接相邻的,而是在同一个方法中),但是与 NSDate、NSDateFormatter 或任何这些对象变量没有任何关系。只有几个 NSTextFields 的导出。

我完全不知所措。任何帮助将不胜感激!

最佳答案

您的格式字符串必须与您在 dateFromString: 方法中提供的字符串匹配。在上一个版本中,格式字符串中没有逗号,但测试字符串中有逗号(大概在 [activeFanbirthday] 中。

关于xcode - NSDateFormatter 在三次使用中的第三次返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527212/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com