Im using an NSCalendar to display the week day, I have no problem displaying the weekday in an integer, but i am confused as to how i might get it to tell me the weekday, i.e. “Thursday.” I read that %A, and %a might do the trick but I do not know how to implement them. My code is below.
NSDate* now = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =[gregorian components:NSWeekdayCalendarUnit fromDate:now];
NSInteger weekday = [weekdayComponents weekday];
myLabel.text = [NSString stringWithFormat:@"%02d", weekday];
I use myLabel to display the string on the Iphone, but if there is a better way please let me know.
Thanks for the help.
James
To display day of week you actually need to use
NSDateFormatterclass, set ‘EEEE’ format to get full day name (like Thursday) or ‘EEE’ – for shortened (like Thu). Very sample code: