为什么NSDateFormatter返回nil? [英] Why does NSDateFormatter return nil?

查看:137
本文介绍了为什么NSDateFormatter返回nil?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在执行这段代码后,在iPhone模拟器3.1.2上 lDateFormatted nil

  NSString * lDateString = @Wed,17 Feb 2010 16:02:01; 
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@EEE,dd MMM yyyy hh:mm:ss];
NSDate * lDateFormatted = [dateFormatter dateFromString:lDateString];



任何想法赞赏,
感谢

解决方案

您可能想要使用 HH 小时,这是0-23 /军事风格
可能需要在您的逗号周围放置单个蜱,如','



参考: the UTS doc and 日期格式指南


Why is lDateFormatted nil on iPhone simulator 3.1.2 after executing this piece of code?

NSString *lDateString = @"Wed, 17 Feb 2010 16:02:01";
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy hh:mm:ss"];
NSDate *lDateFormatted = [dateFormatter dateFromString: lDateString ];

Any ideas appreciated, Thanks

解决方案

You probably want to be using HH for hours, that's 0-23 / military style Also, you may need to put single ticks around your comma like ','

Reference: the UTS doc and date formatting guide.

这篇关于为什么NSDateFormatter返回nil?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆