Is it possible to find the current week of the year using NSDateComponents and setWeek: ? As setWeek uses a number form 1 - 52 every week in the year, how can I find the number representing this week?
A:
If I understand your question correctly, I think the solution is simple, you create a NSDateComponents of the current date and you get the week.
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSWeekCalendarUnit;
NSDateComponents *dateComponents = [calendar components:unitFlags
fromDate:[NSDate date] // for current date
options:0];
NSUInteger week = [dateComponents week]; // here is your week
vodkhang
2010-08-24 09:42:33
Ahh! I see, well I just found out, before looking back here, I could do it this way:
Josh Kahane
2010-08-24 10:05:47
NSDateFormatter *weekFormatter = [[NSDateFormatter alloc] init]; [weekFormatter setDateFormat:@"w"]; NSString *weekDateString = [weekFormatter stringFromDate:curDate]; [weekFormatter release];
Josh Kahane
2010-08-24 10:06:25