Created
February 9, 2014 20:49
-
-
Save samjarman/8905726 to your computer and use it in GitHub Desktop.
Returns a suffix for a day of the month, eg 1st, 2nd, 2rd, 4th
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 *)suffixForDayInDate:(NSDate *)date{ | |
NSInteger day = [[[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] components:NSDayCalendarUnit fromDate:date] day]; | |
if (day >= 11 && day <= 13) { | |
return @"th"; | |
} else if (day % 10 == 1) { | |
return @"st"; | |
} else if (day % 10 == 2) { | |
return @"nd"; | |
} else if (day % 10 == 3) { | |
return @"rd"; | |
} else { | |
return @"th"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment