Using the Gregorian calendar, I am able to get the number of the day of the week (i.e. 1 for Sunday and 2 for Monday, etc.) but I am not able to find a function that displays the name of week then the number. Can anyone help?
Here is my co开发者_JAVA技巧de to get the number of day:
NSDate *dates = [gregorian dateFromComponents:component];
NSDateComponents *weekdayComponents =[gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:dates];
NSUInteger *weekdays = [weekdayComponents weekday];
NSString *dayw=[NSString stringWithFormat:@"%1i",weekdays];
NSLog(@"%@",dayw);
Create an NSDateFormatter
. The format string @"EEEE"
will output the name of the day of the week.
精彩评论