我想解析一個RSS源,但日期很難解析。日期字符串是:publishedDate = "2013-01-08T20:09:02.000Z"
NSDateFormatter麻煩?
這裏是我的代碼:
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時間。
什麼是'publishedDate'? – wigging
串... 2013-01-08T20:09:02.000Z –