Return to Snippet

Revision: 40811
at February 8, 2011 09:08 by OreganoJones


Initial Code
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setWeekday: x];
[dateComponents setWeekdayOrdinal:1];
[dateComponents setYear:2011];
[dateComponents setMonth:2];

NSDate *tempDate = [gregorian dateFromComponents:dateComponents];

NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"EEEE"];

NSString *retval = [format stringFromDate:tempDate];

Initial URL


Initial Description
A name of a given day of the week.
With the week day x, build an NSDate for the first x in February 2011.
Format the NSDate so that the weekday name is generated.
Is this really necessary, or is it a tragically roundabout detour?

Initial Title
Return the weekday name from the weekday number.

Initial Tags


Initial Language
Objective C