Skip to content

Instantly share code, notes, and snippets.

@NikolaKirev
Created April 12, 2013 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikolaKirev/5369345 to your computer and use it in GitHub Desktop.
Save NikolaKirev/5369345 to your computer and use it in GitHub Desktop.
Using Localised Weekday Name Strings
- (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