Last active
January 28, 2016 02:52
-
-
Save JigsChanchiya/6044680 to your computer and use it in GitHub Desktop.
date formatting with suffix
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
-(NSString *)StringFromDate:(NSDate *)DateLocal{ | |
NSDateFormatter *prefixDateFormatter = [[[NSDateFormatter alloc] init] autorelease]; | |
[prefixDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; | |
[prefixDateFormatter setDateFormat:@"MMMM d., yyyy"];//June 13th, 2013 | |
NSString * prefixDateString = [prefixDateFormatter stringFromDate:DateLocal]; | |
NSDateFormatter *monthDayFormatter = [[[NSDateFormatter alloc] init] autorelease]; | |
[monthDayFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; | |
[monthDayFormatter setDateFormat:@"d"]; | |
int date_day = [[monthDayFormatter stringFromDate:DateLocal] 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]; | |
prefixDateString = [prefixDateString stringByReplacingOccurrencesOfString:@"." withString:suffix]; | |
NSString *dateString =prefixDateString; | |
// NSLog(@"%@", dateString); | |
return dateString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment