为什么我得到这个 NSDate 的空值?

发布于 2024-12-13 02:31:16 字数 680 浏览 4 评论 0原文

我从一个网络服务返回一个 NSDictionary,在记录时看起来像这样:

NSLog(@"dictionary: %@", dictionary);

给我:

dictionary: {
    BackOrderDate = "1/1/0001 12:00:00 AM";
    Quantity = 15;
}

然后我尝试从中获取一个日期:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSDate *date = [df dateFromString: [dictionary objectForKey:@"BackOrderDate"]];

记录这个给我一个(空),但我知道我的字典有一个值:

NSLog(@"setting back order date:%@ %@",date, [dictionary objectForKey:@"BackOrderDate"]);

给我:

setting back order date:(null) 3/1/2012 12:00:00 AM

在这方面花费了太多时间 - 我错过了什么???

I am getting a NSDictionary back form a web service that looks like this when logged:

NSLog(@"dictionary: %@", dictionary);

Gives me:

dictionary: {
    BackOrderDate = "1/1/0001 12:00:00 AM";
    Quantity = 15;
}

So then I try and get a date from that:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
NSDate *date = [df dateFromString: [dictionary objectForKey:@"BackOrderDate"]];

Logging this gives me a (null) but I know my dictionary has a value:

NSLog(@"setting back order date:%@ %@",date, [dictionary objectForKey:@"BackOrderDate"]);

Gives me:

setting back order date:(null) 3/1/2012 12:00:00 AM

Spending WAY to much time on this - what am I missing????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2024-12-20 02:31:16

我猜你错过了

[df setDateFormat:@"dd/MM/yyyy HH:mm:ss aaa"];

I guess you missed

[df setDateFormat:@"dd/MM/yyyy HH:mm:ss aaa"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文