Skip to content

Instantly share code, notes, and snippets.

@AKupetskiy
Last active May 20, 2016 14:02
Show Gist options
  • Save AKupetskiy/1acd8a743483149c25d1dc4731bd9922 to your computer and use it in GitHub Desktop.
Save AKupetskiy/1acd8a743483149c25d1dc4731bd9922 to your computer and use it in GitHub Desktop.
grab date in format "Wednesday, the 13th July, 2015", find other formats here: http://waracle.net/iphone-nsdateformatter-date-formatting-table/
NSDate *date = [NSDate date];
NSDateFormatter *monthDayFormatter = [NSDateFormatter new];
[monthDayFormatter setDateFormat:@"F"];
int date_day = [[monthDayFormatter stringFromDate:date] intValue];
NSString *suffix_string = @"|st|nd|rd|th|th|th|th|th|th|th|th|th|th|th|th|th|th|th|th|th|st|nd|rd|th|th|th|th|th|th|th|st";
NSArray *suffixes = [suffix_string componentsSeparatedByString: @"|"];
NSString *suffix = [suffixes objectAtIndex:date_day];
NSDateFormatter *firstPart = [NSDateFormatter new];
[firstPart setDateFormat:@"EEEE, F"];
NSString *firstStr = [firstPart stringFromDate:date];
NSDateFormatter *secondPart = [NSDateFormatter new];
[secondPart setDateFormat:@" MMMM, yyyy"];
NSString *secondStr = [secondPart stringFromDate:date];
NSString *dateString = [NSString stringWithFormat:@"%@%@%@",firstStr,suffix,secondStr];
NSLog(@"%@", dateString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment