NSDateFormatter dateFromString: 是否应该为无效字符串返回 nil ?

发布于 2024-09-06 19:47:19 字数 488 浏览 1 评论 0原文

根据类参考,dateFromString 方法返回“使用接收器当前设置解释的字符串的日期表示形式”。使用以下代码:

NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
[formatter setDateFormat:@"MMddyy"];
NSDate * date = [formatter dateFromString:@"2010-04-27T17:45:44.763"];

在 SDK 3.1.3 中返回 nil,但在 SDK 3.2 上返回 2010-01-20 00:00:00 -0300。 3.2 版本的行为是否正确?

According to the class reference, dateFromString method returns "A date representation of string interpreted using the receiver’s current settings". Using the following code:

NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
[formatter setDateFormat:@"MMddyy"];
NSDate * date = [formatter dateFromString:@"2010-04-27T17:45:44.763"];

in SDK 3.1.3 returns nil, but on SDK 3.2 it returns 2010-01-20 00:00:00 -0300. Is the 3.2 version the correct behavior?

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

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

发布评论

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

评论(1

↘人皮目录ツ 2024-09-13 19:47:19

我认为它应该返回零。使用 SDK 4。

I think it is supposed to return nil. Use SDK 4.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文