marciokoko marciokoko - 1 year ago 65
iOS Question

How do I take a date and extract the day in iOS"

I have a webservice that returns the date in this format:


How do i figure out what day this corresponds to?

Answer Source

An alternate method for getting the weekday can be:

NSString *myDateString = @"2013-04-14";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSDate *date = [dateFormatter dateFromString:myDateString];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];

NSInteger weekday = [components weekday];
NSString *weekdayName = [dateFormatter weekdaySymbols][weekday - 1];

NSLog(@"%@ is a %@", myDateString, weekdayName);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download