gpt4 book ai didi

ios - dateFromString 打印出 "(null)"

转载 作者:行者123 更新时间:2023-11-29 04:18:47 27 4
gpt4 key购买 nike

我知道对此有很多问题,但似乎没有一个答案对我有用。这是我的代码(iOS SDK 6.0)

NSDateFormatter *df = [NSDateFormatter alloc];
[df setDateFormat:@"yyyy-MM-dd"];
[df setFormatterBehavior:NSDateFormatterBehavior10_4];
[df setTimeZone:[NSTimeZone defaultTimeZone]];
[df setLocale:[NSLocale currentLocale];
NSDate *TERMIN = [NSDate alloc];
TERMIN = [df dateFromString:T]; //'T' is date in string NSLog(...,T) is 2002-05-05

当我通过 NSLog 输出 TERMIN 时,输出为 (null)

最佳答案

您忘记初始化 NSDateFormatter 对象

NSDateFormatter *df = [[NSDateFormatter alloc] init];

关于ios - dateFromString 打印出 "(null)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13297755/

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