Moshe Moshe - 1 year ago 86
iOS Question

How do I get the day of the week with Cocoa Touch?

How do I get the day of the week as a string in Objective-C?

Answer Source
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];  
[dateFormatter setDateFormat:@"EEEE"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);

outputs current day of week as a string in locale dependent on current regional settings.

To get just a week day number you must use NSCalendar class:

NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [gregorian components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
int weekday = [comps weekday];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download