NSDateFormatter 不工作
好吧,我觉得问这个问题有点愚蠢,但知道为什么这不起作用:
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"mmmm dd, yyyy"];
NSDate *myDateFromString = [formatter dateFromString:creditDate.text];
NSLog(@"%@", myDateFromString);
[self.credit setCertificationDate: myDateFromString];
}
它返回 null
Ok I feel kind of dumb asking this, but any idea why this is not working:
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"mmmm dd, yyyy"];
NSDate *myDateFromString = [formatter dateFromString:creditDate.text];
NSLog(@"%@", myDateFromString);
[self.credit setCertificationDate: myDateFromString];
}
It returns null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
格式和字符串不匹配,因为“m”是分钟,“M”是月份。因此“August 18 2012”无法解释,请改为“MMMM dd yyyy”。您可以在 unicode.org
我总是明确设置一个区域设置:
只要您不解析月份名称,无论您的真实名称是否正确,都没有关系如果提供显式格式字符串,则区域设置为 en_US。
更多提示:
Format and string don't match because "m" is minute and "M" is month. So "August 18 2012" can't be interpreted, take "MMMM dd yyyy" instead You can check formats at unicode.org
I always set a locale explicitly:
As long as you don't parse month names, it doesn't matter if your real locale is en_US if supplying an explicit format string.
Some more hints: