Skip to content

Instantly share code, notes, and snippets.

@samjarman
Created February 9, 2014 20:49
Show Gist options
  • Save samjarman/8905726 to your computer and use it in GitHub Desktop.
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
- (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