我从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;
此处pubDate
为NSString
当我使用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)
答案 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]];
}