2012-03-09 59 views
0

采取的NSDate我有串@"Sun, 15 Jan 2012 17:09:48 +0000"我想从约会吧.. 我能做些什么 我试图不能从dateString

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"DDD, DD MMM YYYY HH:MM:SS +HHMM"]; 
NSDate *date = [dateFormat dateFromString:stringDate]; 
but date was nslogged with null 
+1

你能给我们日期试图解析的字符串吗?这可能有助于确定它为什么返回null。 – 2012-03-09 14:34:42

回答

1

您的格式不正确,here is why

Sun, 15 Jan 2012 17:09:48 +0000 
DDD, DD MMM YYYY HH:MM:SS +HHMM 
^^^ ^^  ^^^^ ^^ ^^ ^^^^^ < Treating the last 2 digits of the timezone as months 
^^^ ^^  ^^^^ ^^ ^^ ^^^ < Treating the first 2 digits of the timezone as hours 
^^^ ^^  ^^^^ ^^ ^^^< Hardcoding the + (timezone can handle that) 
^^^ ^^  ^^^^ ^^ ^^ < Using fractional seconds (not a big deal) 
^^^ ^^  ^^^^ ^^ < Using months instead of minutes 
^^^ ^^  ^^^^ < Using weak year instead of calendar year 
^^^ ^^ < Using day of year instead of day of the month 
^^^ < Using day of year instead of day of the week 

这里是正确的格式"EEE, dd MMM yyyy HH:mm:ss ZZZ"