NSDateFormatter 问题? [英] NSDateFormatter Trouble?
本文介绍了NSDateFormatter 问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析 RSS 提要,但日期很难解析.日期字符串为:publishedDate = "2013-01-08T20:09:02.000Z"
I am trying to parse an RSS feed, but the date is hard to parse. The date string is: publishedDate = "2013-01-08T20:09:02.000Z"
这是我的代码:
NSDateFormatter *utc = [[NSDateFormatter alloc] init];
[utc setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[utc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
NSDate *dtUTC = [utc dateFromString: publishedDate];
NSDateFormatter *dfLocal = [[NSDateFormatter alloc] init];
[dfLocal setDateFormat:@"yyyy-MM-dd"];
[dfLocal setTimeZone:[NSTimeZone localTimeZone]];
NSString *time =[dfLocal stringFromDate:dtUTC];
NSLog(@"original UTC %@ now local: %@", dtUTC, time);
为什么 date
返回 nil?另外,我正在尝试将 UTC 时间转换为 CST 时间.
Why is date
returning nil? Also, i am trying to convert UTC time to CST Time.
推荐答案
使用
[utc setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.'000Z'"];
这篇关于NSDateFormatter 问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文