从RSS Feed iOS收到的日期中删除时间格式

时间:2015-06-29 07:36:38

标签: ios objective-c rss

我从RSS Feed获取日期。这是NSString格式。

这就是我的Feed类

@interface Feed : NSObject
{
}

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *link;
@property (nonatomic, strong) NSString *desc;
@property (nonatomic, strong) NSString *pubDate;
@property (nonatomic, strong) NSString *imageUrl;

此处pubDateNSString

当我使用NSlong时,它会给我正确的输出。

Wed, 03 Jun 2015 00:00:00 GMT

现在我要删除此00:00:00 GMT

我尝试了很多并且搜索了很多,但转换后它给了我(null)

我也尝试过这个链接 iOS getting date string from RSS Feed

这是我的日期转换代码,

NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
    [dateFormatter1 setDateFormat:@"dd-MM-yyyy"];
    NSString *stringDate = [dateFormatter1 stringFromDate:feed.pubDate];
    NSLog(@"final %@", stringDate);

最终的输出是

final (null)

1 个答案:

答案 0 :(得分:1)

试试这可能对你有帮助......

 NSLog(@"%@",[self ConvertDate_Format:feed.pubDate]);
 //Pass Your date

-(NSString *)ConvertDate_Format:(NSString*)inputStirng
{
    NSDateFormatter *dformat = [[NSDateFormatter alloc]init];
    [dformat setDateFormat:@"EEE, dd-MMM-yyyy,hh:mm:ss"];
    [dformat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

    NSDateFormatter * dateFormatter1 = [[NSDateFormatter alloc]init];
    [dateFormatter1 setDateFormat:@"yyyy-MM-dd"];
    [dateFormatter1 setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
    return [dateFormatter1 stringFromDate:[dformat dateFromString:inputStirng]];
}