Converts the current date to the day of the week
- (void) Getweek { nscalendar *calendar = [[nscalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now;
NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendarUnit |
nsmonthcalendarunit | nsdaycalendarunit | nsweekdaycalendarunit |
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
now=[NSDate date]; comps = [calendar components:unitflags fromdate:[nsdate date]
];
int year=[comps year];
int week = [comps weekday]; int month = [comps&nbSp;month];
int day = [comps day];
int hour = [comps hour];
int min = [comps minute];
int sec = [comps second]; NSArray * arrWeek=[NSArray
arraywithobjects:@ "Sunday", @ "Monday", @ "Tuesday", @ "Wednesday", @ "Thursday", @ "Friday", @ "Saturday", nil]; nslog (@ "Week:%@", [nsstring stringwithformat:@ "%
@ ", [arrweek objectatindex:[comps weekday] - 1]]); }
This method can not only get the week, but also get the current year, month, time seconds, and so on. More ways to get into the method and see for yourself.