开发者社区> 问答> 正文

在iPhone中转换日期格式

在iPhone中用AFFeedParser解析不同HTML页面的文章

通过解析,获取到的文章日期为字符串:
"Thu, 06 Dec 2012 17:44:22 +0000\n\t\t"

怎么样能把日期转换成这样的格式:Thursday,December 06,2012

展开
收起
爵霸 2016-03-26 10:16:42 2250 0
1 条回答
写回答
取消 提交回答
  • 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

    2019-07-17 19:15:33
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载