NSDateFormatter dateFromString: 是否应该为无效字符串返回 nil ?
根据类参考,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为它应该返回零。使用 SDK 4。
I think it is supposed to return nil. Use SDK 4.