在iPhone中用AFFeedParser
解析不同HTML頁面的文章
通過解析,獲取到的文章日期為字符串:
"Thu, 06 Dec 2012 17:44:22 +0000\n\t\t"
怎麼樣能把日期轉換成這樣的格式:Thursday,December 06,2012
請高人指點。
NSString *yourStringDate = @"Thu, 06 Dec 2012 17:44:22 +0000\n\t\t";
NSString *str =[yourStringDate stringByReplacingOccurrencesOfString:@"\n" withString:@""];
str =[str stringByReplacingOccurrencesOfString:@"\t" withString:@""];
[str retain];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];
NSDate *date = [dateFormatter dateFromString: str];
dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"EEEE,LLLL dd,yyyy"];
NSString *convertedString = [dateFormatter stringFromDate:date];
NSLog(@"Converted String : %@",convertedString);
然後輸出是: Converted String : Thursday,December 06,2012