Date Format Problem
How to get this format of date from NSString;
开发者_StackOverflow中文版Wed, 22 Jun 2011 12:36:00 +0100
to Wed, 22 Jun 2011.
Thanks
Try this code.
NSString *dateStr = @"Wed, 22 Jun 2011 12:36:00 +0100";
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss ZZZ"];
NSDate *date = [dateFormat dateFromString:dateStr];
// Convert date object to desired output format
[dateFormat setDateFormat:@"EEE, MMM d YYYY"];
dateStr = [dateFormat stringFromDate:date];
NSLog(@"Date -- %@",dateStr);
[dateFormat release];
The minimalistic version is E, d MMM y
or to specify 2 digit days and 4 digit years E, dd MMM yyyy
. The Date Formatter uses the Unicode Technical Standard #35.
精彩评论