Last active
May 20, 2016 14:02
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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