Created
April 12, 2013 04:23
-
-
Save NikolaKirev/5369345 to your computer and use it in GitHub Desktop.
Using Localised Weekday Name Strings
This file contains hidden or 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 *)localizedWeekdayStringForDate:(NSDate *)date { | |
// We first get the index of the weekday from NSDateComponents | |
NSCalendar *calendar = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [calendar components:NSWeekdayCalendarUnit fromDate:date]; | |
// The weekdays start from Sunday and from index 1 | |
// 1 - Sunday, 2 - Monday ... | |
int weekdayNumber = [components weekday]; | |
// We need an NSDateFormatter to have access to the localized weekday strings | |
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
// weekdaySymbols returns and array of strings. Keep in mind that they start from Sunday | |
// 0 - Sunday, 1 - Monday, 2 - Tuesday ... | |
NSString *weekdayString = [[formatter weekdaySymbols] objectAtIndex:weekdayNumber - 1]; | |
return weekdayString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment