在我的应用程序中,我使用 NSXMLParser 来解析提要。我也有一个 pubDate,但有许多不同的字符串日期格式:
1. 2013-04-17T12:00:24
2. Wed, 17 Apr 2013 10:15 +0300
3. Wed, 17 Apr 2013 11:07:01 +0200
4. 11/04/2013 18:10:10
这是我的代码:
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc]init];
assert(inputFormatter != nil);
NSLocale *loacle = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"];
assert(loacle != nil);
[inputFormatter setLocale:loacle];
[inputFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
[inputFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSString *dateString = [NSString stringWithFormat:@"%@",currentPubDate];
NSDate *inputDate = [inputFormatter dateFromString:dateString];
NSLocale *hebrow = [[NSLocale alloc]initWithLocaleIdentifier:@"he_IL"];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init];
outputFormatter.locale = hebrow;
[outputFormatter setDateStyle:NSDateFormatterFullStyle];
[outputFormatter setTimeStyle:NSTimeZoneNameStyleShortStandard];
NSString *outputDate = [outputFormatter stringFromDate:inputDate];
问题是:如何调整上述所有内容的日期格式?有什么功能还是我应该手动执行?
提前致谢!